/***************************************************************************
 创建者: 华磊
 开始时间: 2020.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2020.5.8 类的具体实现代码编写

 ***************************************************************************/
#include "ecatmasterigh.h"

#include <time.h>
#include <unistd.h>
#include <iostream>
#include <stdio.h>
#include <assert.h>
#include <QDebug>

#include "powermanager.h"
#include "robotmanager.h"
#include "messagelog.h"

#include "timetool.h"
#include "ethercaterror.h"
#include "robotcontrol.h"
#include "ethercatVendorId.h"
#include "ecatconfig.h"

#include <QSettings>
#include "vrepobject.h"
#include "vrepcontrol.h"
#include "encoderreceiver.h"

#include "ecatbusmanager.h"
#include "pdomapstruct.h"
#define D_DC_ADJUST_WAIT 20
#define D_RefClockFailed_MAX 150
//定时器醒来－sync产生时间，０．５会导致有一半的时间浪费，理想时间＝１－（定时器波动比例）
#define D_IDEAL_PHASE 0.8
#define D_PHASE_ADJUST_KP 0.01
#define D_PHASE_NORMAL_ADJUST_KP 0.01
//2021.5.8 原始调节 D_IDEAL_PHASE 0.5, D_PHASE_ADJUST_KP 0.01
#define D_WKC_ERROR_NOTICE 0
extern RobotControl* robCtl;
extern PowerManager *p_powerManger;


/****************************************************************************/

#define NSEC_PER_SEC (1000000000L)
#define PERIOD_NS (NSEC_PER_SEC / FREQUENCY)

#define DIFF_NS(A, B) (((B).tv_sec - (A).tv_sec) * NSEC_PER_SEC + \
        (B).tv_nsec - (A).tv_nsec)

//#define TIMESPEC2NS(T) ((uint64_t) (T).tv_sec * NSEC_PER_SEC + (T).tv_nsec)



EcatMasterIgh::EcatMasterIgh(int pthread_priority_in, int pthread_schedule_in)
    :EcatMasterBase(pthread_priority_in,pthread_schedule_in)
{
    opLoopCount=0.0;
    isMasterInit=false;
    isMasterPreOp=false;
    isMasterSafeOp=false;
    isSlavesOp=false;
    method2FirstTimeFlag=true;
    wkcLostLimit=1;
    wkc_lost_max=0;
    slave_not_read_counter=0;
    ecatPeriodTimerOffsetMax=200000;
    ecatReceiveMax=300000;
    ecatSendMax=300000;
    ecatCustomMax=800000;

    isFristTimeInOp=0;
    dcAdjustWaitCount=0;
    wkc_count=1000000;
    refClockFailedCount=0;

    QString rootFilePath=D_TCRCONTROLLER_DATA_PATH;
    QString filePath;
    filePath=rootFilePath+GLOBAL_ECAT_BUS_PATH+"checkConfig.ini";
    int tmpReturn=readCheckConfig(filePath,wkcLostLimit,ecatPeriodTimerOffsetMax,
                    ecatReceiveMax,ecatSendMax,ecatCustomMax);
//    wkcLostLimit=1;
    if(1!=tmpReturn)
    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh", 9048, -1 );
        setMasterState( eMasterErr );
    }

    //dataAnalysizer　在motorinterface 和　jointDecouple都有源码
//    dataAnalysizer=new DataAnalysizer("QString _dataComent",
//                                      0,
//                                      0,
//                                      4,
//                                      20000,
//                                      2);

    // qDebug()<<"EcatMasterIgh this=xxxx="<<this;
}

EcatMasterIgh::~EcatMasterIgh()
{
    if( master  )
    {
        rt_printf( "release master...\n" );
        ecrt_release_master(master);
        master=NULL;
    }
    while(!canquit){
        isRun=false;
        osSleepUs(cycle_us);
    }
}

int EcatMasterIgh::getEthercatDebugInfo(EthercatDebugInfo &debugInfo)
{
    debugInfo.slaves_al.resize(isSlaveInOp.size());
    for(int i=0;i<isSlaveInOp.size();i++)
    {
        debugInfo.slaves_al[i]=slavesAl[i];
    }
    debugInfo.masterCommandState=masterCommandState;
    debugInfo.masterCurrentState=masterCurrentState;
    debugInfo.masteroldState=masteroldState;
    debugInfo.stage=stage;
    debugInfo.wkc_count=wkc_count;
    debugInfo.wkc_lost_max=wkc_lost_max;
    debugInfo.wkc_state=wkc_state;
    debugInfo.dcTimerShift=system_time_base;//new
    debugInfo.cycle_us=cycle_us;
    debugInfo.opLoopCount=opLoopCount;
    debugInfo.refTime=refTime;
    debugInfo.dc_diff_ns=dc_diff_ns;
    debugInfo.rerfSumTime=rerfSumTime;
    debugInfo.pcSumTime=pcSumTime;
    debugInfo.pcCycleCount=cycle_counter;//new

    debugInfo.ecatPeriodTimerMonitor_now=ecatPeriodTimerMonitor_now;
    debugInfo.ecatPeriodTimerMonitor_max=ecatPeriodTimerMonitor_max;
    debugInfo.ecatPeriodTimerMonitor_min=ecatPeriodTimerMonitor_min;
    debugInfo.ecatReceiveMonitor_now=ecatReceiveMonitor_now;
    debugInfo.ecatReceiveMonitor_max=ecatReceiveMonitor_max;
    debugInfo.ecatReceiveMonitor_min=ecatReceiveMonitor_min;
    debugInfo.ecatSendMonitor_now=ecatSendMonitor_now;
    debugInfo.ecatSendMonitor_max=ecatSendMonitor_max;
    debugInfo.ecatSendMonitor_min=ecatSendMonitor_min;
    debugInfo.ecatCustomMonitor_now=ecatCustomMonitor_now;
    debugInfo.ecatCustomMonitor_max=ecatCustomMonitor_max;
    debugInfo.ecatCustomMonitor_min=ecatCustomMonitor_min;

//    qDebug()<<"wkcRecordQueue"<<wkcRecordQueue;

    return 1;

}

int EcatMasterIgh::getEthercatSlavesInformation(std::vector<EcatBusDevInfo_gsoap> &slavesInfo)
{
    ec_master_info_t tmp_master_info;
    ecrt_master( master, &tmp_master_info );
    int devcount=tmp_master_info.slave_count;
    if( devcount<1 )
    {
        return 1;
    }
    EcatBusDevInfo_gsoap tmpDeviceInfo;
    ec_slave_info_t slave_info[devcount];
    for(int i=0; i<devcount; i++ )
    {
        if(ecrt_master_get_slave( master, i, &(slave_info[i]) ))
        {
            return -1;
        }
        tmpDeviceInfo.node=slave_info[i].position;
        tmpDeviceInfo.alias=slave_info[i].alias;
        tmpDeviceInfo.vendorId=slave_info[i].vendor_id;
        tmpDeviceInfo.productCode=slave_info[i].product_code;
        tmpDeviceInfo.revisionNumber=slave_info[i].revision_number;
        tmpDeviceInfo.serial_number=slave_info[i].serial_number;
        tmpDeviceInfo.al_state=slave_info[i].al_state;
        tmpDeviceInfo.error_flag=slave_info[i].error_flag;
        tmpDeviceInfo.sync_count=slave_info[i].sync_count;
        tmpDeviceInfo.sdo_count=slave_info[i].sdo_count;
        tmpDeviceInfo.devType=0;
        tmpDeviceInfo.devName=slave_info[i].name;
        tmpDeviceInfo.mappingObjectFile=" ";
        slavesInfo.push_back(tmpDeviceInfo);

    }
    return 1;

}


int EcatMasterIgh::setAlias(int node, unsigned short alias)
{
    char *aliasCmd = NULL;
    QString writeAliasCmd;
    QString pos = QString::number( node );
    QString a = QString::number( alias );

    //    int32_to_bytes(node, pos);
    //    int16_to_bytes(alias, a);
    //sprintf( aliasCmd, "ethercat alias -p %d %d", node, alias );

    writeAliasCmd.push_back("ethercat alias -p ");
    writeAliasCmd.push_back(pos);
    writeAliasCmd.push_back(" ");
    writeAliasCmd.push_back(a);

    qDebug()<<"___"<<writeAliasCmd<<"___"<<endl;

    QByteArray buf = writeAliasCmd.toLatin1();
    aliasCmd = buf.data();

    system( aliasCmd );

    return 1;
}

int EcatMasterIgh::sdoUpload(int node
                             , int rObIndex
                             , int rObSubIndex
                             , LONG64 &rData
                             , int &rDataLen)
{

    rDataLen=4;
    unsigned char pbyData[8]={0};
    int dwRes=0;
    size_t result_size=0;
    unsigned int err;       //SDO错误类型
    int ret = ecrt_master_sdo_upload(master, node, rObIndex,rObSubIndex ,pbyData, rDataLen, &result_size, &err);
    if( ret < 0 )
    {
        rt_printf("sdo: error in COE SDO Upload! %x (0x%x)\n"  , rObIndex, dwRes);
        return 0;
    }

    switch(result_size){
    case 1:  rData = pbyData[0] ;
        break;
    case 2:  rData = bytes_to_uint16( pbyData );
        break;
    case 4: rData =  bytes_to_uint32(  pbyData );
        break;
    case 8:  rData = bytes_to_uint64(  pbyData );
        break;
    default: printf("不支持的sdo数据长度:wDataLen=%d \n",rDataLen);
        return 0;
    }

//    qDebug()<<"pbyData[0]"<<pbyData[0]<<"pbyData[1]"<<pbyData[1]<<"pbyData[2]"<<pbyData[2]
//         <<"pbyData[3]"<<pbyData[3]<<"rDataLen="<<result_size<<"rData="<<rData;

//    qDebug()<<"read sdo rDataReturn="<<rData<<",rObIndex="<<rObIndex<<",rObSubIndex="<<rObSubIndex;
    return 1;
}

int EcatMasterIgh::sdoDownload(int node
                               , int wObIndex
                               , int wObSubIndex
                               , LONG64 wData
                               , int wDataLen)
{
    unsigned char pbyData[8]={0};
    int dwRes=0;
    switch(wDataLen){
    case 1:  pbyData[0] = wData;
        break;
    case 2:  uint16_to_bytes( wData, pbyData );
        break;
    case 4:  uint32_to_bytes( wData, pbyData );
        break;
    case 8:  uint64_to_bytes( wData, pbyData );
        break;
    default: printf("不支持的sdo数据长度:wDataLen=%d \n",wDataLen);
        return 0;
    }

//    qDebug()<<"pbyData[0]"<<pbyData[0]<<"pbyData[1]"<<pbyData[1]<<"pbyData[2]"<<pbyData[2]
//         <<"pbyData[3]"<<pbyData[3]<<"wDataLen="<<wDataLen<<"wData="<<wData;
    unsigned int err;       //SDO错误类型
    int ret = ecrt_master_sdo_download(master,node, wObIndex,wObSubIndex ,pbyData, wDataLen,&err);
    if( ret < 0 )
    {
        rt_printf("sdo: error in COE SDO Download! %x (0x%x)\n"  , wObIndex, dwRes);
        return 0;
    }

    qDebug()<<"write sdo wData="<<wData<<",wObIndex="<<wObIndex<<",wObSubIndex="<<wObSubIndex;;
    return 1;
}

void EcatMasterIgh::masterError()
{
    //rt_printf("ecatmaster err============\n");
    rt_check_master_state();//检查主站状态
}

void EcatMasterIgh::masterInit()
{
    if( isMasterInit )
        return ;

//    system("/etc/init.d/ethercat start");
//    osSleepUs(2000);

//    initialTimerMeasurement();

    t1={0,0};
    t2={0,0};
    t3={0,0};
    t4={0,0};

    master=NULL;        //主站master
    domain=NULL;       //一个结构体域的指针
    domain_p=NULL;        //域数据的指针


    domainOffKeep_noUsed=0;        //域的偏移记录   bit
    currentEntryRegIndex=0;       //偏移数记录    偏移的对象字典
    error_flag_count=3;
    error_flag = 0;
    check_error_delay=5000;
    cycle_counter=0;     //循环计数
    sync_ref_counter=0;      //同步参考计数

    slaveConfigError=0;//初始化配置失败
    domainStateRrror=0;//域数据读写失败

    // memset( &master_state, 0, sizeof(ec_master_state_t) );
    memset( &domain_state, 0, sizeof(ec_domain_state_t) );
    master_state.al_states=0;
    master_state.link_up=0;

    entriesCount=0;

    master = ecrt_request_master(0);
    if( master )
    {
        rt_printf("Requesting master ....................OK!\n");
    }else{
        rt_printf("Requesting master ....................FAIL!\n");
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9012, -1 );
        isMasterInit=false;
        setMasterState( eMasterErr );
        return;
    }

    domain = ecrt_master_create_domain( master );
    if( domain )
    {
        rt_printf("Registering domain ...................OK!\n");
    }else{
        rt_printf("Registering domain ...................FAIL!\n");
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9013, -1 );
        isMasterInit=false;
        setMasterState( eMasterErr );
        return;
    }

    isMasterInit=true;

}

void EcatMasterIgh::masterPreOp()
{
    isFristTimeInOp=0;

    if(isShutDown){
        isRun=false;
    }
    if( isMasterPreOp )
        return ;

    int devcount;

    int ret;
    int devtype;
    QString xml;
    QString name;
    ec_master_info_t master_info;

    ecrt_master( master, &master_info );
    devcount=master_info.slave_count;
    if( devcount<1 )
        return;

    ec_slave_info_t slave_info[devcount];
    for(int i=0; i<devcount; i++ )
    {
        if(ecrt_master_get_slave( master, i, &(slave_info[i]) ))
        {
            rt_printf("ecrt_master_get_slave　failed==========%d\n", i);
            isMasterInit=false;
            addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9042, -1,i );
            setMasterState( eMasterErr );
            return;
        }
        if(i >= robCtl->busManager->aliasList_ethercat.size())
        {
            rt_printf("Warnning: real ecat slaves are more than bus config file!\n");
//            isMasterInit=false;
//            setMasterState( eMasterErr );
        }
        else//hualei modify, because it will cause coredump ,if this condisition satisfy
        {
            devtype = robCtl->busManager->deviceTypeList_ethercat.at( i );
            xml = robCtl->busManager->xmlFilelist_ethercat.at( i );
            if( devtype==E_EcatDev_Servo )
                name="Servo";
            else if( devtype==E_EcatDev_IoModule )
                name="IoModule";
            else if( devtype==E_EcatDev_Coupler )
                name="Coupler";
            else
                name="EcatDev";

            EcatBusDevInfo devInfo=
            {
                name,
                slave_info[i].position,
                slave_info[i].alias,
                slave_info[i].vendor_id ,
                slave_info[i].product_code ,
                slave_info[i].revision_number,
                0,
                devtype,
                xml
            };

            robCtl->busManager->addDevice( devInfo );
        }
    };

    int nodeReturn,aliasReturn;
    int returnKey=robCtl->busManager->checkRobotLogicalAxisMapEthercatAxis(nodeReturn,aliasReturn);

    if( 1==returnKey )
    {
        printf("MSG: scan bus: ethercat 设备映射 ok! \n");
    }
    else if( -2==returnKey )
    {
        printf("ERROR: 机器人轴ethercat motor别名在ecat总线中没有检测到 \n");
        robCtl->ecatmaster->addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9300, -1 ,aliasReturn);
        setMasterState( eMasterErr );
        return;
    }
    else if( -3==returnKey )
    {
        printf("ERROR: ethercat io别名在总线配置中没有找到 \n");
        robCtl->ecatmaster->addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9305, -1 ,aliasReturn);
        setMasterState( eMasterErr );
        return;
    }
    else if( -100==returnKey )
    {
        printf("ERROR: 机器人轴别名busDev.xml中node与实际物理node不一致，请检查物理接线或配置! \n");
        robCtl->ecatmaster->addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9301, -1, aliasReturn,nodeReturn);
        setMasterState( eMasterErr );
        return;
    }
    else if( -101==returnKey )
    {
        printf("ERROR: ethercat io别名busDev.xml中node与实际物理node不一致，请检查物理接线或配置! \n");
        robCtl->ecatmaster->addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9306, -1, aliasReturn,nodeReturn);
        setMasterState( eMasterErr );
        return;
    }
    else
    {
        printf("ERROR: ethercat io别名busDev.xml中node与实际物理node不一致，请检查物理接线或配置! \n");
        robCtl->ecatmaster->addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9306, -1, aliasReturn,nodeReturn);
        setMasterState( eMasterErr );
        return;
    }

    displayBusDevicesInfo();  //打印一些信息

    //    pAliasSetRegRequest.resize( robCtl->busManager->devCount() );
    //    sdo_request_603f.resize( robCtl->busManager->devCount() );
    //    sdo_request_alias.resize( robCtl->busManager->devCount() );
    slave_sc.resize( robCtl->busManager->devCount() );
    isSlaveInOp.resize( robCtl->busManager->devCount() );
    for(int i=0;i<isSlaveInOp.size();i++)
    {
        isSlaveInOp[i]=false;
    }

    //初始化sdo
    int alisOut,indexOut;
    if(1!=downloadServoSdoConfig(alisOut,indexOut))
    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9050, -1 ,alisOut,indexOut);
        setMasterState( eMasterErr );
        return;
    }
    if(1!=initialSdo_EncoderReceiver(alisOut,indexOut))
    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9049, -1 ,alisOut,indexOut);
        setMasterState( eMasterErr );
        return;
    }

    if(1!=downloadIodeviceSdoConfig(alisOut,indexOut))
    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9070, -1 ,alisOut,indexOut);
        setMasterState( eMasterErr );
        return;
    }

    //获取PDO信息
    if( getBusSlavePdoConfig() )
    {
        rt_printf("Read EcatBus devs config ..............OK!\n");
    }
    else
    {
        rt_printf("Read EcatBus devs config .............FAIL!\n");
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9011, -1 );
        setMasterState( eMasterErr );
        return;
    }

    for(int i = 0; i < robCtl->busManager->devCount(); i++ )
    {
        entriesCount += robCtl->busManager->ec_devInfo[i].objConfig.ec_entries.size();
    }
    pdoEntryRegList.resize( entriesCount+1 );//注册每个对象字典信息//must be lager thean entriesCount

    //初始化设备PDO配置
    if( initialBusSlavesPdoConfig() )
    {
        rt_printf("Init device ..........................OK!\n");
    }
    else
    {
        rt_printf("Init device ..........................FAIL!\n");
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9015, -1 );
        setMasterState( eMasterErr );
        return;
    }

//        displayDomainRegConfig();
//        displayEthercatConfig(0);
    //    displayEthercatConfig(1);
    //    displayEthercatConfig(2);
    //    displayEthercatConfig(3);
    //    displayEthercatConfig(4);
    //    displayEthercatConfig(5);
    //    displayEthercatConfig(6);

    //initial servo parameter， this function should not at the end,or ethercat master
    //will go crushed
//    RobotBase* rob;
//    foreach( rob, robCtl->robotsMap )
//    {
//        initialServoParameter(rob);
//    }

#if D_USE_DC_SYNC

    /* Set the initial master time and select a slave to use as the DC
     * reference clock, otherwise pass NULL to auto select the first capable
     * slave. Note: This can be used whether the master or the ref slave will
     * be used as the systems master DC clock.
     */
    dc_start_time_ns = system_time_ns();
    dc_time_ns = dc_start_time_ns;

    /* Attention: The initial application time is also used for phase
     * calculation for the SYNC0/1 interrupts. Please be sure to call it at
     * the correct phase to the realtime cycle.
     */
    ecrt_master_application_time(master, dc_start_time_ns);//激活主站前，需要设置好app时间
    ret=ecrt_master_select_reference_clock( master, NULL);//选择一个参考时钟,激活主站前设置,周磊说每个从站都要设置

    if( ret )
    {
        rt_printf( "failed : ecrt_master_select_reference_clock failed !!选择从站时钟失败!" );
        setMasterState( eMasterErr );
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9072, -1 );
        return;
    }

#endif

    #if D_USE_DC_MASTER_METHOD
    double tmpRatio=cycle_ns;
    tmpRatio*=D_IDEAL_PHASE;
    system_time_base=tmpRatio;
    #endif

    if( activeMaster() )
    {
        rt_printf("Active master ........................OK!\n");
    }
    else
    {
        rt_printf("Active master ........................FAIL!\n");
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh", 9016, -1 );
        setMasterState( eMasterErr );
        return;
    }

    isMasterPreOp=true;

    //dc timer use
    cycle_counter = 0;
    blink = 0;

    return;

}

void EcatMasterIgh::masterSafeOp()
{
    if( isMasterSafeOp )
        return ;
    isMasterSafeOp=true;
}

int EcatMasterIgh::checkTimeMaxLimit()
{
    S_TIME_DATA* dataReceive;
    TimeTool::getInstance()->getTimeData(timer_id_measure[D_TIME_RECEIVE],&dataReceive);
    S_TIME_DATA* dataCustom ;
    TimeTool::getInstance()->getTimeData(timer_id_measure[D_TIME_CUSTOM],&dataCustom);
    S_TIME_DATA* dataSend ;
    TimeTool::getInstance()->getTimeData(timer_id_measure[D_TIME_SEND],&dataSend);
    S_TIME_DATA* dataPeriodTimer ;
    TimeTool::getInstance()->getTimeData(timer_id_measure[D_TIME_TIMER],&dataPeriodTimer);

    int a, b, c,e,f,g;
    e=timer_id_measure[D_TIME_RECEIVE];
    f=timer_id_measure[D_TIME_CUSTOM];
    g=timer_id_measure[D_TIME_SEND];
    a=dataReceive->maxTime;
    b=dataSend->maxTime;
    c=dataCustom->maxTime;

    ecatPeriodTimerMonitor_now=dataPeriodTimer->nowTime;
    ecatPeriodTimerMonitor_max=dataPeriodTimer->maxTime;
    ecatPeriodTimerMonitor_min=dataPeriodTimer->minTime;
    ecatReceiveMonitor_now=dataReceive->nowTime;
    ecatReceiveMonitor_max=dataReceive->maxTime;
    ecatReceiveMonitor_min=dataReceive->minTime;
    ecatSendMonitor_now=dataSend->nowTime;
    ecatSendMonitor_max=dataSend->maxTime;
    ecatSendMonitor_min=dataSend->minTime;
    ecatCustomMonitor_now=dataCustom->nowTime;
    ecatCustomMonitor_max=dataCustom->maxTime;
    ecatCustomMonitor_min=dataCustom->minTime;

    if(dataPeriodTimer->nowTime>cycle_ns+ecatPeriodTimerOffsetMax)//300us
    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9004, -1,
               dataPeriodTimer->nowTime/1000.0
               ,(cycle_ns+ecatPeriodTimerOffsetMax)/1000.0,cycle_ns,cycle_us);

    }
    if(dataPeriodTimer->nowTime<cycle_ns-ecatPeriodTimerOffsetMax)//300us
    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9003, -1,
               dataPeriodTimer->nowTime/1000.0
               ,(cycle_ns-ecatPeriodTimerOffsetMax)/1000.0,cycle_ns,cycle_us);

    }

    if(dataReceive->nowTime>ecatReceiveMax)//300us
    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9302, -1,
               dataReceive->nowTime/1000.0,ecatReceiveMax/1000.0 );

    }
    if(dataSend->nowTime>ecatSendMax)//300us
    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9303, -1,
               dataSend->nowTime/1000.0,ecatSendMax/1000.0 );
    }
    //if(dataCustom->maxTime>800000)//800us
    if(dataCustom->nowTime >  ecatCustomMax)//超过80%报警

    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9304, -1,
               dataCustom->nowTime/1000.0, ecatCustomMax/1000.0);
//        printf("error : ethercat custom time exceed limit------------------------------");
    }

    return 1;
}

void EcatMasterIgh::dcMethod1()
{
    //弊端　有的伺服（step) 可能是不允许动态修正它的时间，偶尔卡一下。
    // write application time to master
//    struct timespec currentTime;
//    clock_gettime(CLOCK_MONOTONIC, &currentTime);//HUALEI : THIS IS ESSENTIAL timespec2ns(currentTime)
    ecrt_master_application_time(master,system_time_ns());//
    if (sync_ref_counter) {
        sync_ref_counter--;
    }
    else
    {
        sync_ref_counter = 1; // sync every X cycle
        ecrt_master_sync_reference_clock(master);//
    }

}



/** Synchronise the distributed clocks
 */
void EcatMasterIgh::sync_distributed_clocks(void)
{

//    uint32_t ref_time = 0;
    uint64_t prev_app_time = dc_time_ns;


    dc_time_ns = system_time_ns();

//#if SYNC_MASTER_TO_REF
    dcAdjustWaitCount++;
    // get reference clock time to synchronize master cycle.
    //如果获取不了参考时间(任意网线有故障时,igh打印会导致实时问题)
    int resultClock=ecrt_master_reference_clock_time(master, &refTime);
    if(false==isInitialedOk  || dcAdjustWaitCount>D_DC_ADJUST_WAIT)//
    {
        dcAdjustWaitCount=0;

        if(0!=resultClock)
        {
            refClockFailedCount++;
            if(refClockFailedCount>D_RefClockFailed_MAX)
            {
                setMasterState( eMasterErr );
                addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9071, -1,D_RefClockFailed_MAX );
                printf("refClockFailedCount>20,failed ,,,ecrt_master_reference_clock_time %d \n",resultClock);
            }
        }
        else
        {
            dc_diff_ns = (uint32_t) prev_app_time - refTime;
        }

    }


//#else
//    // sync reference clock to master
//    ecrt_master_sync_reference_clock_to(master, dc_time_ns);
//#endif

    // call to sync slaves to ref slave
//    ecrt_master_sync_slave_clocks(master);
}

/*****************************************************************************/

/** Return the sign of a number
 *
 * ie -1 for -ve value, 0 for 0, +1 for +ve value
 *
 * \retval the sign of the value
 */
#define sign(val) \
    ({ typeof (val) _val = (val); \
    ((_val > 0) - (_val < 0)); })

/*****************************************************************************/

/** Update the master time based on ref slaves time diff
 *
 * called after the ethercat frame is sent to avoid time jitter in
 * sync_distributed_clocks()
 */
void EcatMasterIgh::update_master_clock(void)
{
#if SYNC_MASTER_TO_REF
    // calc drift (via un-normalised time diff)
    int32_t delta = dc_diff_ns - prev_dc_diff_ns;
    prev_dc_diff_ns = dc_diff_ns;

    // normalise the time diff
    dc_diff_ns =
        ((dc_diff_ns + (cycle_ns / 2)) % cycle_ns) - (cycle_ns / 2);

    // only update if primary master
    if (dc_started) {

        // add to totals
        dc_diff_total_ns += dc_diff_ns;
        dc_delta_total_ns += delta;
        dc_filter_idx++;

        if (dc_filter_idx >= DC_FILTER_CNT) {
            // add rounded delta average
            dc_adjust_ns +=
                ((dc_delta_total_ns + (DC_FILTER_CNT / 2)) / DC_FILTER_CNT);

            // and add adjustment for general diff (to pull in drift)
            dc_adjust_ns += sign(dc_diff_total_ns / DC_FILTER_CNT);

            // limit crazy numbers (0.1% of std cycle time)
            if (dc_adjust_ns < -1000) {
                dc_adjust_ns = -1000;
            }
            if (dc_adjust_ns > 1000) {
                dc_adjust_ns =  1000;
            }

            // reset
            dc_diff_total_ns = 0LL;
            dc_delta_total_ns = 0LL;
            dc_filter_idx = 0;
        }

        // add cycles adjustment to time base (including a spot adjustment)
        system_time_base += dc_adjust_ns + sign(dc_diff_ns);
    }
    else {
        dc_started = (dc_diff_ns != 0);

        if (dc_started) {
            // output first diff
            printf("First master diff: %d.\n", dc_diff_ns);

            // record the time of this initial cycle
            dc_start_time_ns = dc_time_ns;
        }
    }
#endif
}

void EcatMasterIgh::update_master_clock_hualei()
{
    double tmpAdjustKp=D_PHASE_NORMAL_ADJUST_KP;
//    if(false==isInitialedOk)
//    {
//        tmpAdjustKp=D_PHASE_ADJUST_KP;
//    }
    // 华磊，修正定时器，使SM2-SYNC的相位在正中间
        //使用PID调节原理，调节太快可能失去稳态。
        int tmpError=dc_diff_ns-cycle_ns*D_IDEAL_PHASE;
        //1调节过快; 0.01时有; 0.001时上电调节比较慢;sm2-sync的时间受到custom时间的影响，但是只要一直稳定大于０就不会卡顿．
        int tmpOutput=tmpError*tmpAdjustKp;
        system_time_base+=tmpOutput;//调节方向是否对？


//            // calc drift (via un-normalised time diff)
//            int32_t delta = dc_diff_ns - prev_dc_diff_ns;
//            prev_dc_diff_ns = dc_diff_ns;

//            // normalise the time diff
//            dc_diff_ns =
//                ((dc_diff_ns + (cycle_ns / 2)) % cycle_ns) - (cycle_ns / 2);

//            // only update if primary master
//            if (dc_started) {

//                // add to totals
//                dc_diff_total_ns += dc_diff_ns;
//                dc_delta_total_ns += delta;
//                dc_filter_idx++;

//                if (dc_filter_idx >= DC_FILTER_CNT) {
//                    // add rounded delta average
//                    dc_adjust_ns +=
//                        ((dc_delta_total_ns + (DC_FILTER_CNT / 2)) / DC_FILTER_CNT);

//                    // and add adjustment for general diff (to pull in drift)
//                    dc_adjust_ns += sign(dc_diff_total_ns / DC_FILTER_CNT);

//                    // limit crazy numbers (0.1% of std cycle time)
//                    if (dc_adjust_ns < -1000) {
//                        dc_adjust_ns = -1000;
//                    }
//                    if (dc_adjust_ns > 1000) {
//                        dc_adjust_ns =  1000;
//                    }

//                    // reset
//                    dc_diff_total_ns = 0LL;
//                    dc_delta_total_ns = 0LL;
//                    dc_filter_idx = 0;
//                }

//                // add cycles adjustment to time base (including a spot adjustment)
//                system_time_base += dc_adjust_ns + sign(dc_diff_ns);
//            }
//            else {
//                dc_started = (dc_diff_ns != 0);

//                if (dc_started) {
//                    // output first diff
//                    printf("First master diff: %d.\n", dc_diff_ns);

//                    // record the time of this initial cycle
//                    dc_start_time_ns = dc_time_ns;
//                }
//            }

}

#define D_NO_CHECK_COUNT 20000
#define D_OP_WAIT_COUNT 50
void EcatMasterIgh::masterOp()
{

    stage=E_ETHERCAT_STAGE_OP_IN;

     ecrt_master_application_time(master, wakeup_time);

#if D_IF_DEBUG
    if(D_NO_CHECK_COUNT-3<=isFristTimeInOp )//&& true==isSlavesOp
    {
        TimeTool::getInstance()->recordPeirodTime(timer_id_measure[D_TIME_TIMER]);

    }


    TimeTool::getInstance()->recordInTime(timer_id_measure[D_TIME_RECEIVE]);
#endif
    ecrt_master_receive(master);
    stage=E_ETHERCAT_STAGE_RECEIVE_OK;
    ecrt_domain_process(domain);
    stage=E_ETHERCAT_STAGE_DOMAIN_PROCESS_OK;

    rt_check_domain_state();//检查域状态
    stage=E_ETHERCAT_STAGE_CHECK_DOMAIN_OK;
    cycle_counter++;
    if( cycle_counter > 1000 )
    {
        cycle_counter=0;
        rt_check_master_state();//检查主站状态
        stage=E_ETHERCAT_STAGE_CHECK_MASTER_OK;

        if(!isSlavesOp)
        {
            static int noOpCount=0;
            if( 0 == rt_check_slaves_state(true) )
            {
                noOpCount=0;
                //检查从站状态
                isSlavesOp = true;
                //初始化完成判断
                if(false==isInitialedOk && true==isSlavesOp)
                {
                    isInitialedOk=true;
                    addMsg(ENUM_MSG_REMIND, "EcatMaster", "EcatMasterIgh" , 9002, -1 );
                }
            }
            else
            {
                noOpCount++;
                if(noOpCount>D_OP_WAIT_COUNT)
                {
                    addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9066, -1,D_OP_WAIT_COUNT );
                    setMasterState(eMasterInit);
                    noOpCount=0;
                }
            }
        }
    }

#if D_IF_DEBUG
    TimeTool::getInstance()->recordOutTime(timer_id_measure[D_TIME_RECEIVE]);
    TimeTool::getInstance()->recordInTime(timer_id_measure[D_TIME_CUSTOM]);
#endif

    if(true==isInitialedOk)
    {
        //hualei todo ,cost time 1679us.
        updateDomainData(); //读写过程数据 (帧数据交互)
        stage=E_ETHERCAT_STAGE_UPDATE_DOMAIN_OK;
    }

#if D_IF_DEBUG
    TimeTool::getInstance()->recordOutTime(timer_id_measure[D_TIME_CUSTOM]);
    TimeTool::getInstance()->recordInTime(timer_id_measure[D_TIME_SEND]);
#endif



    stage=E_ETHERCAT_STAGE_DC_UPDATE_OK;
    ecrt_domain_queue(domain);//HUALEI : THIS IS ESSENTIAL

    #if D_USE_DC_MASTER_METHOD
    dcMethod1();
    #endif

    #if D_USE_DC_SLAVE1_METHOD
    // sync distributed clock just before master_send to set
    // most accurate master clock time
    sync_distributed_clocks();
    #endif

    //同步其余slaves 到ref参考时间
    ecrt_master_sync_slave_clocks(master);

    stage=E_ETHERCAT_STAGE_DOMAIN_QUEUE_OK;
    ecrt_master_send(master);

    #if D_USE_DC_SLAVE1_METHOD
    // update the master clock
    // Note: called after ecrt_master_send() to reduce time
    // jitter in the sync_distributed_clocks() call
//    update_master_clock();
    if(isSlavesOp)
    {
         update_master_clock_hualei();//所有从站进入op后才开始调整相位。
    }

    #endif

#if D_IF_DEBUG
    TimeTool::getInstance()->recordOutTime(timer_id_measure[D_TIME_SEND]);
#endif
    if(D_NO_CHECK_COUNT==isFristTimeInOp)
    {
        checkTimeMaxLimit();
    }
    if(isFristTimeInOp<D_NO_CHECK_COUNT)
    {
        isFristTimeInOp++;
    }
    opLoopCount++;
    stage=E_ETHERCAT_STAGE_OP_OUT;

}



void EcatMasterIgh::displayBusDevicesInfo( )
{
#if !D_IF_DEBUG
    return;
#endif
    qDebug()<<    "\n========displayDevicesInfo=========  "  ;
    qDebug()<<    "Ethercat总线上所有设备="<<robCtl->busManager->devCount();

    for(int i=0;i< robCtl->busManager->devCount();i++)
    {
        switch( robCtl->busManager->ec_devInfo[i].devInfo.devType )
        {
        case  E_EcatDev_TypeErr:
            qDebug()<<"设备:"<< i <<"不可用*";
            break;
        case  E_EcatDev_NotUsed:
            qDebug()<<"设备:"<< i <<"未使用*";
            break;
        case  E_EcatDev_New:
            qDebug()<<"设备:"<< i <<"新增*";
            break;
        case  E_EcatDev_Used:
            qDebug()<<"设备:"<< i <<"已使用";
            break;
        case  E_EcatDev_Coupler:
            qDebug()<<"设备:"<< i <<"耦合器";
            break;
        case  E_EcatDev_Servo:
            qDebug()<<"设备:"<< i <<"伺服";
            break;
        case  E_EcatDev_IoModule:
            qDebug()<<"设备:"<< i <<"io模块";
            break;
        default:
            break;
        }
        qDebug()<< robCtl->busManager->ec_devInfo[i].devInfo.devName;
    }

}

void EcatMasterIgh::displayDomainRegConfig(  )
{
#if !D_IF_DEBUG
    return;
#endif

    int domainSize = ecrt_domain_size( domain );

    qDebug()<< "\n========displayDomainRegConfig=========  "  ;
    qDebug()<< "domainSize="<<domainSize;

    for( int i=0;i<pdoEntryRegList.size()-1 ; i++)
    {
        qDebug( "\nDomain Regs[ %d ]={ ", i);
        if( pdoEntryRegList.at(i).offset )
        {
            qDebug() << "index : 0x"+QString("%1").setNum(pdoEntryRegList.at(i).index, 16)
                     << "subindex : 0x"+QString("%1").setNum(pdoEntryRegList.at(i).subindex, 16)
                     << "offset :  "+QString("%1").setNum( *(pdoEntryRegList.at(i).offset), 10 );
        }

        if( pdoEntryRegList.at(i).bit_position )
        {
            qDebug() << "bit_position :  "+QString("%1").setNum( *(pdoEntryRegList.at(i).bit_position), 10 );
        }
        qDebug() << " }";
    }

}

void EcatMasterIgh::displayEthercatConfig( int nd  )
{
#if !D_IF_DEBUG
    return;
#endif

    if( nd >=robCtl->busManager->devCount() )
        return;
#if 0


#else

    qDebug()<< "\n================= dev:" << nd ;
    // qDebug()<< "Slave Alias="<<nodeMapAlias.value(nd);
    qDebug()<< "Dev Type="<< robCtl->busManager->ec_devInfo[nd].devInfo.devType;
    qDebug()<< "Vendor Id="<<"0x"+QString("%1").setNum(robCtl->busManager->ec_devInfo[nd].devInfo.vendorId, 16);
    qDebug()<< "Product Code="<<"0x"+QString("%1").setNum(robCtl->busManager->ec_devInfo[nd].devInfo.productCode, 16);
    qDebug()<< "Revision Number="<<"0x"+QString("%1").setNum(robCtl->busManager->ec_devInfo[nd].devInfo.revisionNumber, 16);
    qDebug()<< "\n";
    qDebug( "ec_entries[ %d ]=",  nd) ;

    int tcount=0;
    for(int j=0;j<robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.size(); j++)
    {
        for(int k=0;k<robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).n_pdos;k++)
        {
            for(int n=0;n<robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
            {
                if( (robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos[k].entries+n)!=NULL )
                {
                    qDebug()<<  tcount++<<"    { "
                             << "0x"+QString("%1").setNum(robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos[k].entries[n].index, 16)
                             << "0x"+QString("%1").setNum(robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex, 16)
                             << robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length
                             << " }";
                }
            }
        }
    }

    tcount=0;
    int entryOffset=0;
    qDebug()<< "\n";
    qDebug( "ec_pdos[ %d ]=" , nd) ;
    for(int j=0;j<robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.size(); j++)
    {
        for(int k=0;k<robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).n_pdos;k++)
        {
            if( (robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos+k) !=NULL)
            {
                for(int n=0;n<robCtl->busManager->ec_devInfo[nd].objConfig.ec_entries.size();n++ )
                {
                    if( robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos[k].entries== &(robCtl->busManager->ec_devInfo[nd].objConfig.ec_entries[n]) )
                    {
                        entryOffset= n;
                        break;
                    }
                }

                qDebug()<< tcount++<< "    { "
                        << "0x"+QString("%1").setNum(robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos[k].index, 16)
                        << robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos[k].n_entries
                        << "ec_entries+"+QString::number(entryOffset)
                        << " }";
            }
        }
    }

    tcount=0;
    int pdoOffset=0;
    QString dir;
    QString wd;
    qDebug()<<"\n";
    qDebug("ec_syncs[ %d ]=", nd) ;
    for(int j=0;j<robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.size(); j++)
    {
        for(int k=0;k<robCtl->busManager->ec_devInfo[nd].objConfig.ec_pdos.size();k++ )
        {
            if( robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos== &(robCtl->busManager->ec_devInfo[nd].objConfig.ec_pdos[k]) )
            {
                pdoOffset= k;
                break;
            }
        }
        if( robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).watchdog_mode==EC_WD_DEFAULT )
            wd= "EC_WD_DEFAULT";
        else if( robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).watchdog_mode==EC_WD_ENABLE )
            wd= "EC_WD_ENABLE";
        else if( robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).watchdog_mode==EC_WD_DISABLE )
            wd= "EC_WD_DISABLE";

        if( robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).dir==EC_DIR_INVALID )
            dir= "EC_DIR_INVALID";
        else if( robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).dir==EC_DIR_OUTPUT )
            dir= "EC_DIR_OUTPUT";
        else if( robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).dir==EC_DIR_INPUT )
            dir= "EC_DIR_INPUT";
        else if( robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).dir==EC_DIR_COUNT )
            dir= "EC_DIR_COUNT";

        if(robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos!=NULL && robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).n_pdos)
            // if(robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).pdos!=NULL )
        {
            qDebug()<< tcount++<<"    { "
                    << robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).index
                    << dir
                    << robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).n_pdos
                    << "ec_pdos+"+QString::number(pdoOffset)
                    << wd
                    << " }";
        }else{
            qDebug()<< tcount++<<"    { "
                    << robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).index
                    << dir
                    << robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.at(j).n_pdos
                    << "NULL"
                    << wd
                    << " }";
        }
    }
#endif
    qDebug()<< "\n===== display config end =======\n "   ;
}

bool EcatMasterIgh::getBusSlavePdoConfig( )
{

    for(int i=0;i< robCtl->busManager->devCount();i++)
    {
        S_EcatDevInfo* ecdev= &(robCtl->busManager->ec_devInfo[i]);
        if(  E_EcatDev_Servo==ecdev->devInfo.devType )
        {
            getEcatMotorPdoConfig(robCtl->busManager->ec_devInfo[i]);

        }
        else  if(  E_EcatDev_IoModule==ecdev->devInfo.devType )
        {
            if(1!=getEcatIoDeviceConfig(robCtl->busManager->ec_devInfo[i],i))
            {
                qDebug()<<"getEcatIoDeviceConfig failed!!!";
            }

        }
        else  if(  E_EcatDev_EncoderReceiver==ecdev->devInfo.devType )
        {//todoForVision
//            if(1!=getIoDevicePdoConfigByCode(robCtl->busManager->ec_devInfo[i],i))
//            {
//                qDebug()<<"getEncoderReceiverPdoConfig failed!!!";
//            }
            if(1!=getEcatDeviceConfig_byEeprom(robCtl->busManager->ec_devInfo[i],i))
            {
                qDebug()<<"getEncoderReceiverPdoConfig failed!!!";
            }

        }

    }
    return true;
}

int EcatMasterIgh::getEcatIoPdoConfig_byCode(S_EcatDevInfo &devicePdoInfo,
                                             uint32_t vendor,uint32_t productCodeIn)
{
    qDebug()<<"EcatMasterIgh::getEcatIoPdoConfig_byCode,vendor"<<vendor<<"productCodeIn"<<productCodeIn;

    switch( vendor )
    {

    case D_VENDOR_ID_LeiSai_IO:
    {
        if(D_VENDOR_ID_LeiSai_IO_EM32DXE1==productCodeIn)//not used,ethercat csturct查看不到pdo映射，好像不行，必须用twincat下载xml到eeprom
        {
            devicePdoInfo.objConfig.ec_entries.resize( sizeof(leisai_io_entries)/sizeof(ec_pdo_entry_info_t) );
            devicePdoInfo.objConfig.ec_pdos.resize( sizeof(leisai_io_pdos)/sizeof(ec_pdo_info_t)  );
            devicePdoInfo.objConfig.ec_syncs.resize( sizeof(leisai_io_syncs)/sizeof(ec_sync_info_t)  );

            memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), leisai_io_entries, sizeof(leisai_io_entries) );
            memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), leisai_io_pdos, sizeof(leisai_io_pdos) );
            memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), leisai_io_syncs, sizeof(leisai_io_syncs) );

            devicePdoInfo.objConfig.ec_pdos[0].entries
                    =&(devicePdoInfo.objConfig.ec_entries[0]);
            devicePdoInfo.objConfig.ec_pdos[1].entries
                    =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

            devicePdoInfo.objConfig.ec_syncs.resize(2);
            devicePdoInfo.objConfig.ec_syncs[0].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
            devicePdoInfo.objConfig.ec_syncs[1].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
        }
        else if(D_VENDOR_ID_LeiSai_IO_EM32DIE4==productCodeIn)
        {
            devicePdoInfo.objConfig.ec_entries.resize( sizeof(leisaiio_die4_pdo_entries)/sizeof(ec_pdo_entry_info_t) );
            devicePdoInfo.objConfig.ec_pdos.resize( sizeof(leisaiio_die4_pdos)/sizeof(ec_pdo_info_t)  );
            devicePdoInfo.objConfig.ec_syncs.resize( sizeof(leisaiio_die4_syncs)/sizeof(ec_sync_info_t)  );

            memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), leisaiio_die4_pdo_entries, sizeof(leisaiio_die4_pdo_entries) );
            memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), leisaiio_die4_pdos, sizeof(leisaiio_die4_pdos) );
            memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), leisaiio_die4_syncs, sizeof(leisaiio_die4_syncs) );

            devicePdoInfo.objConfig.ec_pdos[0].entries
                    =&(devicePdoInfo.objConfig.ec_entries[0]);

            devicePdoInfo.objConfig.ec_syncs.resize(4);
            devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[2].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        }
        else if(D_VENDOR_ID_LeiSai_IO_EM32DOE4==productCodeIn)
        {
            devicePdoInfo.objConfig.ec_entries.resize( sizeof(leisaiio_doe4_pdo_entries)/sizeof(ec_pdo_entry_info_t) );
            devicePdoInfo.objConfig.ec_pdos.resize( sizeof(leisaiio_doe4_pdos)/sizeof(ec_pdo_info_t)  );
            devicePdoInfo.objConfig.ec_syncs.resize( sizeof(leisaiio_doe4_syncs)/sizeof(ec_sync_info_t)  );

            memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), leisaiio_doe4_pdo_entries, sizeof(leisaiio_doe4_pdo_entries) );
            memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), leisaiio_doe4_pdos, sizeof(leisaiio_doe4_pdos) );
            memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), leisaiio_doe4_syncs, sizeof(leisaiio_doe4_syncs) );

            devicePdoInfo.objConfig.ec_pdos[0].entries
                    =&(devicePdoInfo.objConfig.ec_entries[0]);

            devicePdoInfo.objConfig.ec_syncs.resize(4);
            devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
            devicePdoInfo.objConfig.ec_syncs[3].pdos=NULL;
        }
        else
        {
            qDebug()<<"\n error no recognize productCodeIn"<<productCodeIn;
            return -1;
        }

    }
        break;
    case D_VENDOR_ID_SHANGHAI_XINGYANG:
    {
        if(D_VENDOR_ID_SHANGHAI_XINGYANG_SMARTIOR1==productCodeIn)
        {
            devicePdoInfo.objConfig.ec_entries.resize( sizeof(xinyangIOR1_pdo_entries)/sizeof(ec_pdo_entry_info_t) );
            devicePdoInfo.objConfig.ec_pdos.resize( sizeof(xinyangIOR1_pdos)/sizeof(ec_pdo_info_t)  );
            devicePdoInfo.objConfig.ec_syncs.resize( sizeof(xinyangIOR1_syncs)/sizeof(ec_sync_info_t)  );

            memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), xinyangIOR1_pdo_entries, sizeof(xinyangIOR1_pdo_entries) );
            memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), xinyangIOR1_pdos, sizeof(xinyangIOR1_pdos) );
            memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), xinyangIOR1_syncs, sizeof(xinyangIOR1_syncs) );

//            devicePdoInfo.objConfig.ec_pdos[0].entries
//                    =&(devicePdoInfo.objConfig.ec_entries[0]);
//            devicePdoInfo.objConfig.ec_pdos[1].entries
//                    =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

//            devicePdoInfo.objConfig.ec_syncs.resize(2);
//            devicePdoInfo.objConfig.ec_syncs[0].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
//            devicePdoInfo.objConfig.ec_syncs[1].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);

            devicePdoInfo.objConfig.ec_pdos[0].entries
                    =&(devicePdoInfo.objConfig.ec_entries[0]);
            devicePdoInfo.objConfig.ec_pdos[1].entries
                    =&(devicePdoInfo.objConfig.ec_entries[3]);
            devicePdoInfo.objConfig.ec_pdos[2].entries
                    =&(devicePdoInfo.objConfig.ec_entries[6]);

            devicePdoInfo.objConfig.ec_syncs.resize(4);
            devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
            devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
        }
        else
        {
            qDebug()<<"\n error no recognize productCodeIn"<<productCodeIn;
            return -1;
        }

    }
        break;
    default:
    {
        qDebug()<<"\n警告:使用通用的io配置参数";
        return -1;
    }
    }



    return 1;
}

int EcatMasterIgh::getEcatIoPdoConfig_xml(S_EcatDevInfo &devicePdoInfo, QString xmlFilePath)
{
//    readEcatDevSettingsXml(xmlfile , i) ;
}

bool EcatMasterIgh::regRealtimeRead( ec_reg_request_t *pRegRequest,
                                     int pos, void *val , int byteNum, int regadr )
{
    Q_UNUSED(pos)
    switch( ecrt_reg_request_state( pRegRequest ))
    {
    case EC_REQUEST_UNUSED:
        ecrt_reg_request_read( pRegRequest, regadr, byteNum );
        return false;
    case EC_REQUEST_BUSY:
        //rt_printf("Still Read busy...\n");
        return false;
    case EC_REQUEST_SUCCESS:
    {
        switch( byteNum )
        {
        case 1:
        {
            *(quint8 *)val = EC_READ_U8( ecrt_reg_request_data( pRegRequest ));
        }
            break;
        case 2:
        {
            *(unsigned short *)val = EC_READ_U16( ecrt_reg_request_data( pRegRequest ) );
        }
            break;
        case 4:
        {
            *(unsigned int *)val = EC_READ_U32( ecrt_reg_request_data( pRegRequest ) );
        }
            break;
        case 8:
        {
            *(uint64_t *)val = EC_READ_U64( ecrt_reg_request_data( pRegRequest ) + 7);
        }
            break;
        default:
            break;
        }
        ecrt_reg_request_read( pRegRequest, regadr, byteNum );
    }
        return true;
    case EC_REQUEST_ERROR:
        //rt_printf( "fail to read reg\n" );
        ecrt_reg_request_read( pRegRequest, regadr, byteNum );   //重复写
        return false;
    }
    return true;
}

bool EcatMasterIgh::regRealtimeWrite( ec_reg_request_t *pRegRequest, int pos, void *val , int byteNum, int regadr )
{
    Q_UNUSED(pos)
    switch( ecrt_reg_request_state( pRegRequest ) )
    {
    case EC_REQUEST_UNUSED:
        ecrt_reg_request_write( pRegRequest, regadr, byteNum );
        return false;
    case EC_REQUEST_BUSY:
        //rt_printf("Still Read busy...\n");
        return false;
    case EC_REQUEST_SUCCESS:
    {
        switch( byteNum )
        {
        case 1:
        {
            EC_WRITE_U8( ecrt_reg_request_data( pRegRequest ) , *(quint8 *)val);
        }
            break;
        case 2:
        {
            EC_WRITE_U16( ecrt_reg_request_data( pRegRequest ), *(unsigned short *)val);
        }
            break;
        case 4:
        {
            EC_WRITE_U32( ecrt_reg_request_data( pRegRequest ), *(unsigned int *)val);
        }
            break;
        case 8:
        {
            EC_WRITE_U64( ecrt_reg_request_data( pRegRequest ), *(uint64_t *)val);
        }
            break;
        default:
            break;
        }
        ecrt_reg_request_write( pRegRequest, regadr, byteNum );
    }
        rt_printf( "..\n" );
        return true;
    case EC_REQUEST_ERROR:
        //rt_printf( "fail to read reg\n" );
        ecrt_reg_request_write( pRegRequest, regadr, byteNum );   //重复写
        return false;
    }
    return true;
}

bool EcatMasterIgh::sdoRealtimeRead( ec_sdo_request_t *pSdoRequest,
                                     int pos, void *val , int byteNum, int offset )
{
    Q_UNUSED(pos)
    switch( ecrt_sdo_request_state( pSdoRequest ))
    {
    case EC_REQUEST_UNUSED:
        ecrt_sdo_request_read( pSdoRequest );
        return false;
    case EC_REQUEST_BUSY:
        //rt_printf("Still Read busy...\n");
        return false;
    case EC_REQUEST_SUCCESS:
    {
        switch( byteNum )
        {
        case 1:
        {
            quint8 *tmp = (quint8 *)val;
            *tmp = EC_READ_U8( ecrt_sdo_request_data( pSdoRequest ) + offset);
        }
            break;
        case 2:
        {
            unsigned short *tmp1 = (unsigned short *)val;
            *tmp1 = EC_READ_U16( ecrt_sdo_request_data( pSdoRequest ) + offset);
        }
            break;
        case 4:
        {
            unsigned int *tmp2 = (unsigned int *)val;
            *tmp2 = EC_READ_U32( ecrt_sdo_request_data( pSdoRequest ) + offset);
        }
            break;
        default:
            break;
        }
        ecrt_sdo_request_read( pSdoRequest );
    }
        return true;
    case EC_REQUEST_ERROR:
        //            rt_printf( "fail to read sdo\n" );
        ecrt_sdo_request_read( pSdoRequest );   //重复写
        return false;
    }
    return true;
}

bool EcatMasterIgh::sdoRealtimeWrite( ec_sdo_request_t *pSdoRequest, int pos,  int v , int byteNum, int offset )
{
    Q_UNUSED(byteNum)
    Q_UNUSED(pos)
    switch( ecrt_sdo_request_state( pSdoRequest ))
    {
    case EC_REQUEST_UNUSED:
        ecrt_sdo_request_write( pSdoRequest );
        return false;
    case EC_REQUEST_BUSY:
        //rt_printf("Still Read busy...\n");
        return false;
    case EC_REQUEST_SUCCESS:
        EC_WRITE_U32( ecrt_sdo_request_data( pSdoRequest ) + offset, (unsigned int)v );
        ecrt_sdo_request_write( pSdoRequest );
        //rt_printf( "success to write sdo\n" );
        return true;
    case EC_REQUEST_ERROR:
        //rt_printf( "fail to write sdo\n" );
        ecrt_sdo_request_write( pSdoRequest );   //重复写
        return false;
    }
    return true;
}

int EcatMasterIgh::getResultFromSystemCall(const char* pCmd, char* pResult, int size)
{

#if 0
    //命令行返回为空时无法.
    int fd[2];
    pipe(fd);
    fflush(stdout);

    int bak_fd = dup(STDOUT_FILENO);
    int new_fd = dup2(fd[1], STDOUT_FILENO);

#if 0
    QByteArray buf(pCmd);
    if(buf.isEmpty() )
    {
        qDebug()<<"cmd is empty!";
        return 0;
    }
    system( buf.constData() );
#else
    system( pCmd );
#endif

    read(fd[0], pResult, size);
    pResult[strlen(pResult) -1] = 0;
    dup2(bak_fd,new_fd);

#else
    FILE *fstream=NULL;
    if(NULL==(fstream=popen( pCmd  ,"r")))
    {
        return -1;
    }

    while(NULL!=fgets(pResult, size, fstream))
    {
        ;//fstream >> ;//printf("%s",buff);
    }

    pclose(fstream);
#endif

    return 0;
}

bool EcatMasterIgh::initialBusSlavesPdoConfig( )
{
    if( master==NULL  )
    {
        rt_printf("error : master==NULL \n" );
        return false;
    }

    slaveConfigError=0;
    for( int i = 0; i < robCtl->busManager->devCount(); i++ )
    {
        //获取从站信息
        ec_slave_config_t *sc = NULL;

        S_EcatDevInfo* eDev= &robCtl->busManager->ec_devInfo[i];
        if(eDev==NULL)
            return false;

        // int node = i;//robCtl->busManager->ec_devInfo[i].devInfo.node;
        qDebug()<< "\n slaveConfig ,devtype="  <<i     << eDev->devInfo.devType
                <<eDev->devInfo.alias <<eDev->devInfo.vendorId <<eDev->devInfo.productCode;

        sc = ecrt_master_slave_config( master, 0 , i, eDev->devInfo.vendorId, eDev->devInfo.productCode );

        if( !sc )
        {
            rt_printf("Slave config failed: %d\n", eDev->devInfo.alias );
            slaveConfigError |= 1<<i;
            continue;
        }else{
            slave_sc[i]= sc;
        }

        //        //REG资源申请
        //        pAliasSetRegRequest[i] = ecrt_slave_config_create_reg_request(sc,2);
        //        if( !pAliasSetRegRequest[i] )
        //        {
        //            rt_printf("pAliasSetRegRequest reg Request fail !");
        //        }
        //        //SDO资源申请
        //        sdo_request_603f[i] = ecrt_slave_config_create_sdo_request(sc, 0x603f, 0x0, 2 );
        //        if( NULL == sdo_request_603f[i] )
        //        {
        //            rt_printf("   alarm code read error: sdo Request fail , -1! \n");
        //        }
        //        ecrt_sdo_request_timeout(sdo_request_603f[i], 1000);

        //reg: watch dog
        //        pAliasSetRegRequest[node] = ecrt_slave_config_create_reg_request(sc,2);
        //        if( !pAliasSetRegRequest[node] )
        //        {
        //            rt_printf("pAliasSetRegRequest reg Request fail !");
        //            return false;
        //        }
        //        return true;

        switch( eDev->devInfo.devType )
        {
        case E_EcatDev_Servo:
        {
            initialMotorSdo( i );//设置quickStop类通用sdo参数值
            if(1!=entryRegConfig( i ))
            {
                rt_printf("error: entryRegConfig E_EcatDev_Servo！\n");
                addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9067, -1  );
                setMasterState(eMasterErr_LOCK);
                return false;
            }
            syncsConfig( sc, i );
        }
            break;
        case E_EcatDev_IoModule:
        {
            if(1!=entryRegConfig( i ))
            {
                rt_printf("error: entryRegConfig E_EcatDev_IoModule\n");
                addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9068, -1  );
                setMasterState(eMasterErr_LOCK);
                return false;
            }
            syncsConfig( sc, i );//pdo配置不对会报错。
        }
            break;
        case E_EcatDev_EncoderReceiver:
        {//todoForVison
            if(1!=entryRegConfig( i ))
            {
                rt_printf("error: entryRegConfig E_EcatDev_EncoderReceiver\n");
                addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9069, -1  );
                setMasterState(eMasterErr_LOCK);
                return false;
            }
            syncsConfig( sc, i );//pdo配置不对会报错。
        }
            break;
        default:
            break;
        }

    }

    qDebug()<< "=========domain regs size:"<<pdoEntryRegList.size() << currentEntryRegIndex;
    memset( &pdoEntryRegList[ pdoEntryRegList.size()-1 ], 0, sizeof(ec_pdo_entry_reg_t) ) ;
    //pdo配置不对时，这里会coredump.
    int ret=ecrt_domain_reg_pdo_entry_list( domain, pdoEntryRegList.begin() );   //tcdomainRegs

    if( ret  )
    {
        rt_printf( "PDO entry registration fail: %d!\n",ret);
        slaveConfigError  = 0x01;
        return false;
    }

    if( slaveConfigError ){
        qDebug()<<"slaveConfigError : "<<slaveConfigError   ;
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9019, -1, slaveConfigError );
    }

    return slaveConfigError?false:true;
}

bool EcatMasterIgh::activeMaster( )
{
    int ret = ecrt_master_activate(master);
    if(ret<0 )
    {
        rt_printf( "Active master error: fail to get activate master!\n");
        return false;
    }
    if (!(domain_p = ecrt_domain_data(domain)) )
    {
        rt_printf( "Active master error: fail to get domain data pointer!\n");
        return false;
    }

    clock_gettime(CLOCK_MONOTONIC , &cycleTimespec);//
    return true;
}

void EcatMasterIgh::initialMotorSdo( int nd )
{
    // int vendor = robCtl->busManager->ec_devInfo[nd].devInfo.vendorId;

    //运行模式
    sdoDownload( nd, 0x6060, 0, eServoModeCsp ,1 );
//    sdoDownload( nd, 0x6060, 0, eServoModeCsv,1 );
    if(0)
    {
        //跟随误差
        sdoDownload( nd, 0x6065, 0, 0xffffffff, 4 );
        //设置0x605a,quick stop的设置
        sdoDownload( nd, 0x605a,0, 2, 2 );
        //设置0x6085,quick stop的减速度
        sdoDownload( nd, 0x6085, 0, 4000000000, 4 );
        //shutdown 减速停止选项   使用0=0x3506 ,1=0x6084, 三洋报错
        sdoDownload( nd, 0x605b, 0, 0, 2 );
        //op disable 减速停止选项   使用0=0x3506 ,1=0x6084
        sdoDownload( nd, 0x605c, 0, 0, 2 ); //tc 伺服报下载失败　todo
        //  fault （错误） 减速停止选项   使用 0=0x3510 , 1=0x6084, 2=0x6085 ,三洋报错
        sdoDownload( nd, 0x605e, 0, 2, 2);
        //halt（内部暂停指令） 减速停止选项   使用 1=0x6084 , 2=0x6085, 3=0x6072
        sdoDownload( nd, 0x605d, 0, 2, 2);

        // 0x607e  SX  旋转方向
        // 0x3015  SX  1是相对，  0x7 0，2是绝对
        // 0x605a  SX  快速停止减速度
        // 0x605d  SX  错误发生减速方式
    }


}

int EcatMasterIgh::entryRegConfig(int nd )
{

    if( nd > robCtl->busManager->devCount())
    {
        return -1;
    }


    S_EcatDevInfo* info= &(robCtl->busManager->ec_devInfo[nd]);

    if(info->devInfo.devType == E_EcatDev_Servo )
    {
        return entryRegConfig_motor(nd ,info);

    }
    else if(info->devInfo.devType == E_EcatDev_IoModule )
    {
        return entryRegConfig_ioModule(nd ,info);

    }
    else if(info->devInfo.devType == E_EcatDev_EncoderReceiver )
    {
        return entryRegConfig_EncoderReceiver(nd ,info);

    }


    return -1;
//    qDebug()<<"\n offCntKeep====="<<offCntKeep;
//    for(int jj=0;jj<offCntKeep;jj++)
//     {
//         qDebug()<<"\n builddomainRegs[" << jj << "]offCntKeep ].alias"  <<builddomainRegs[ jj ].alias ;
//         qDebug()<<"\n builddomainRegs[" << jj << "]offCntKeep ].position"<< builddomainRegs[ jj ].position ;
//         qDebug()<<"\n builddomainRegs[" << jj << "]offCntKeep ].vendor_id"<<builddomainRegs[ jj ].vendor_id ;
//         qDebug()<<"\n builddomainRegs[" << jj << "]offCntKeep ].product_code"<< builddomainRegs[ jj ].product_code ;
//         qDebug()<<"\n builddomainRegs[" << jj << "]offCntKeep ].index"<<builddomainRegs[ jj ].index ;
//         qDebug()<<"\n builddomainRegs[" << jj << "]offCntKeep ].subindex"<< builddomainRegs[ jj ].subindex ;
//    }
    // qDebug()<<"\n\nxxxxxxxxxxxxxxddd= domainOffKeep====="<<domainOffKeep<<offCntKeep;
}
#define D_CHANNEL_OFFSET 0x800
int EcatMasterIgh::entryRegConfig_motor(int nd,S_EcatDevInfo* info)
{
    int tmpVectorIndex=-1;
    robCtl->busManager->getDeviceArryIndexByNodeId_ethercatDevice(nd,tmpVectorIndex);
    EcatMotor* motor= robCtl->busManager->ec_motors[tmpVectorIndex];

    motor->setVendorId(info->devInfo.vendorId);

    for(int j=0;j<info->objConfig.ec_syncs.size(); j++)
    {
        for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
        {

            if((info->objConfig.ec_syncs.at(j).pdos+k)==NULL)
                continue;

            for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
            {
                if( (info->objConfig.ec_syncs.at(j).pdos[k].entries+n) ==NULL )
                    continue;
                bool isMatch=false;
                for(int channelIndex=0;channelIndex<D_MAX_MOTOR_CHANNEL;channelIndex++)
                {

                    if( D_MAP_OBJECT_CONTROL_WORD+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        // motor->offset.offsetControlWorldSet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetControlWorldSet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_TARGET_POSITION+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        // motor->offset.offsetTargetPosSet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetTargetPosSet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_OPERATION_MODE+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        // motor->offset.offsetAmpModeSet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetAmpModeSet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_STATUS_WORD+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        // motor->offset.offsetServoStateGet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetServoStateGet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_POSITION_ACTUAL+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        // motor->offset.offsetEncoderGet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetEncoderGet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_TORQUE_ACTUAL+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        //  motor->offset.offsetTorqueGet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetTorqueGet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_DIGITAL_INPUT+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        // motor->offset.offsetMotorDiGet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetMotorDiGet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_VELOCITY_ACTUAL+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        // motor->offset.offsetSpeedGet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetSpeedGet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_MODES_OF_OPERATION_DISPLAY+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        // motor->offset.offsetAmpModeGet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetAmpModeGet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_ERROR_CODE_603F+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index
                             || D_MAP_OBJECT_ERROR_CODE_sanyo == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index)
                    {
    //                    motor->pdoDomainOffset.offsetErrorCodeGet = domainOffKeep_noUsed/8;//没有作用
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetErrorCodeGet[channelIndex];
                        isMatch=true;
                    }

                    else if( D_MAP_OBJECT_FOLLOWINGERROR_ACTUAL+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        // motor->offset.offsetFollowingErrorGet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetFollowingErrorGet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_EXTERNAL_FEEDBACK+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {
                        // motor->offset.offsetFollowingErrorGet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetExternalFeedback[channelIndex];
                        isMatch=true;
                    }

                    else if( D_MAP_OBJECT_VELOCITY_OFFSET+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {//写 速度漂移
                        // motor->offset.offsetSpeedOffSet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetSpeedOffSet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_TORQUE_OFFSET+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {//写扭矩漂移
                        //  motor->offset.offsetTorqueOffSet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetTorqueOffSet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_TARGET_TORQUE+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {//写目标扭矩
                        // motor->offset.offsetTargetTorqueSet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetTargetTorqueSet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_TARGET_SPEED+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    { //写目标速度
                        // motor->offset.offsetTargetSpeedSet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetTargetSpeedSet[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_HOME_METHOD+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    { //回零方式
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetHomeMethod[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_MODE_DISPLAY+channelIndex*D_CHANNEL_OFFSET == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    { //控制模式显示
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetModeDisplay[channelIndex];
                        isMatch=true;
                    }
                    else if( D_MAP_OBJECT_QINGNENGDECHUAN_NULL_8BIT== info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    { //假字节
                        // motor->offset.offsetTargetSpeedSet = domainOffKeep/8;
                        pdoEntryRegList[ currentEntryRegIndex ].offset = &motor->pdoDomainOffset.offsetNullData8bitSet;
                        isMatch=true;
                    }
//                    qDebug()<<"to match"<<info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index<<tmpAddressValue;


                }

                if(false==isMatch)
                {

                        qDebug()<<"no find valid entry,,,motor entriesConfig error:"<<j<<k<<n
                               <<info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index ;
                        return -1;
                }



                /*  else if( D_MAP_OBJECT_ＭAX_SPEED == ecdev->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {//最大速度
                        motor->offset.offsetMaxSpeedSet = domainOffKeep/8;
                        builddomainRegs[ offCntKeep ].offset = &motor->offset.offsetMaxSpeedSet;

                    }*/

                pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                pdoEntryRegList[ currentEntryRegIndex ].bit_position = NULL;

                domainOffKeep_noUsed += info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;
                currentEntryRegIndex++;
            }
        }
    }
    return 1;
}

int EcatMasterIgh::entryRegConfig_ioModule(int nd,S_EcatDevInfo* info)
{
     int tmpVectorIndex=-1;
     robCtl->busManager->getDeviceArryIndexByNodeId_ethercatDevice(nd,tmpVectorIndex);
     EcatIo* io = robCtl->busManager->ec_ioModule[tmpVectorIndex];
     int diCounter = 0;
     int diBitOffset=1;
     int doCounter = 0;
     int doBitOffset=1;
     int aiCounter = 0;
     int aoCounter = 0;
     int encoderCounter=0;
     int controlCounter=0;
     int statusCounter=0;

     if(1!=getIoModuleDiDoSize(nd,info,diCounter,diBitOffset,doCounter,doBitOffset,aiCounter,
                         aoCounter,encoderCounter,controlCounter,statusCounter))
     {
         return -1;
     }

     io->initialProperty(info->devInfo.vendorId,info->devInfo.productCode,diCounter,doCounter,aiCounter,aoCounter,
                         encoderCounter,controlCounter,statusCounter);

     //配置不对会导致coredump
     assignPdoDomainOffset(nd,info,diBitOffset,doBitOffset,io);

     return 1;
}

int EcatMasterIgh::entryRegConfig_EncoderReceiver(int nd, S_EcatDevInfo *info)
{
    //todoForVision
    int tmpVectorIndex=-1;
    robCtl->busManager->getDeviceArryIndexByNodeId_ethercatDevice(nd,tmpVectorIndex);
    EncoderReceiver* receiver= robCtl->busManager->encoderReceivers[tmpVectorIndex];

    receiver->setVendorId(info->devInfo.vendorId);

    for(int j=0;j<info->objConfig.ec_syncs.size(); j++)
    {
        for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
        {

            if((info->objConfig.ec_syncs.at(j).pdos+k)==NULL)
                continue;

            for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
            {
                if( (info->objConfig.ec_syncs.at(j).pdos[k].entries+n) ==NULL )
                    continue;

                if( D_doOutput_index == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                {
                    pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.doOutput;
                }
                else if( D_Encoder_Val_index == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                {
                    if(D_Encoder0_Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Encoder0_Val;
                    }
                    else if(D_Encoder1_Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Encoder1_Val;
                    }
                    else if(D_Encoder2_Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Encoder2_Val;
                    }

                }
                else if( D_Ltc0_index == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                {
                    if(D_HighSpeed_IN0_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.HighSpeed_IN0;
                    }
                    else if(D_Ltc0_Finished_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc0_Finished;
                    }
                    else if(D_Ltc0_Encoder0Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc0_Encoder0Val;
                    }
                    else if(D_Ltc0_Encoder1Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc0_Encoder1Val;
                    }
                    else if(D_Ltc0_Encoder2Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc0_Encoder2Val;
                    }

                }
                else if( D_Ltc1_index == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                {
                    if(D_HighSpeed_IN1_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.HighSpeed_IN1;
                    }
                    else if(D_Ltc1_Finished_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc1_Finished;
                    }
                    else if(D_Ltc1_Encoder0Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc1_Encoder0Val;
                    }
                    else if(D_Ltc1_Encoder1Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc1_Encoder1Val;
                    }
                    else if(D_Ltc1_Encoder2Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc1_Encoder2Val;
                    }

                }
                else if( D_Ltc2_index == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                {
                    if(D_HighSpeed_IN2_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.HighSpeed_IN2;
                    }
                    else if(D_Ltc2_Finished_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc2_Finished;
                    }
                    else if(D_Ltc2_Encoder0Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc2_Encoder0Val;
                    }
                    else if(D_Ltc2_Encoder1Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc2_Encoder1Val;
                    }
                    else if(D_Ltc2_Encoder2Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc2_Encoder2Val;
                    }

                }
                else if( D_Ltc3_index == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                {
                    if(D_HighSpeed_IN3_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.HighSpeed_IN3;
                    }
                    else if(D_Ltc3_Finished_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc3_Finished;
                    }
                    else if(D_Ltc3_Encoder0Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc3_Encoder0Val;
                    }
                    else if(D_Ltc3_Encoder1Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc3_Encoder1Val;
                    }
                    else if(D_Ltc3_Encoder2Val_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Ltc3_Encoder2Val;
                    }

                }
                else if( D_Cmp0_index == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                {
                    if(D_HighSpeed_ReadOut0_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.HighSpeed_ReadOut0;
                    }
                    else if(D_Cmp0_FIFO_Exist_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Cmp0_FIFO_Exist;
                    }
                    else if(D_Cmp0_Finished_Number_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Cmp0_Finished_Number;
                    }
                    else if(D_Cmp0_Current_CmpData_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Cmp0_Current_CmpData;
                    }


                }
                else if( D_Cmp1_index == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                {
                    if(D_HighSpeed_ReadOut1_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.HighSpeed_ReadOut1;
                    }
                    else if(D_Cmp1_FIFO_Exist_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Cmp1_FIFO_Exist;
                    }
                    else if(D_Cmp1_Finished_Number_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Cmp1_Finished_Number;
                    }
                    else if(D_Cmp1_Current_CmpData_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Cmp1_Current_CmpData;
                    }


                }
                else if( D_Cmp2_index == info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                {
                    if(D_HighSpeed_ReadOut2_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.HighSpeed_ReadOut2;
                    }
                    else if(D_Cmp2_FIFO_Exist_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Cmp2_FIFO_Exist;
                    }
                    else if(D_Cmp2_Finished_Number_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Cmp2_Finished_Number;
                    }
                    else if(D_Cmp2_Current_CmpData_subindex==info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex)
                    {
                         pdoEntryRegList[ currentEntryRegIndex ].offset = &receiver->domainOffset.Cmp2_Current_CmpData;
                    }


                }

                else
                {

                    qDebug()<<"encoderReceiver entriesConfig error \n";
                    return -1;
                }

                /*  else if( D_MAP_OBJECT_ＭAX_SPEED == ecdev->objConfig.ec_syncs.at(j).pdos[k].entries[n].index )
                    {//最大速度
                        motor->offset.offsetMaxSpeedSet = domainOffKeep/8;
                        builddomainRegs[ offCntKeep ].offset = &motor->offset.offsetMaxSpeedSet;

                    }*/

                pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                pdoEntryRegList[ currentEntryRegIndex ].bit_position = NULL;

                domainOffKeep_noUsed += info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;
                currentEntryRegIndex++;
            }
        }
    }
    return 1;
}

int EcatMasterIgh::getIoModuleDiDoSize(int nd, S_EcatDevInfo *info, int &diSize, int &diBitOffset,
                                       int &doSize, int &doBitOffset,int &aiSizeOut,int &aoSizeOut,
                                       int &encoderSizeOut,int &controlSizeOut,int &statusSizeOut)
{
    diSize = 0;
    doSize = 0;
    aiSizeOut=0;
    aoSizeOut=0;
    encoderSizeOut=0;
    controlSizeOut=0;
    statusSizeOut=0;

    switch( info->devInfo.vendorId )
    {
    case D_VENDOR_ID_YODA:
    {
        if(D_VENDOR_ID_YODA_IO_I16O16==info->devInfo.productCode)
        {
            diBitOffset=16;
            doBitOffset=16;
            diSize = 16;
            doSize = 16;
            aiSizeOut=0;
            aoSizeOut=0;
            encoderSizeOut=0;
            controlSizeOut=0;
            statusSizeOut=0;
            return 1;
        }
        else
        {
            qDebug()<<"error,,,,D_VENDOR_ID_YODA unknow devInfo.productCode"<<info->devInfo.productCode;
            return -1;
        }

        break;
    }

        case D_VENDOR_ID_LeiSai_IO:
        {
            if(D_VENDOR_ID_LeiSai_IO_EM06AXE1==info->devInfo.productCode)
            {
                diBitOffset=16;
                doBitOffset=16;
                diSize = 0;
                doSize = 0;
                aiSizeOut=16;//4个独立通道，每个通道有４个采样值。
                aoSizeOut=2;
                encoderSizeOut=0;
                controlSizeOut=1;
                statusSizeOut=1;
                return 1;
            }
            else if(D_VENDOR_ID_LeiSai_IO_EM32DXE1==info->devInfo.productCode)
            {
                diBitOffset=16;
                doBitOffset=16;
                diSize = 16;
                doSize = 16;
                aiSizeOut=0;
                aoSizeOut=0;
                encoderSizeOut=0;
                controlSizeOut=0;
                statusSizeOut=0;
                return 1;
            }
            else if(D_VENDOR_ID_LeiSai_IO_EM32DXE4==info->devInfo.productCode)
            {
                diBitOffset=16;
                doBitOffset=16;
                diSize = 16;
                doSize = 16;
                aiSizeOut=0;
                aoSizeOut=0;
                encoderSizeOut=0;
                controlSizeOut=0;
                statusSizeOut=0;
                return 1;
            }
            else if(D_VENDOR_ID_LeiSai_IO_EM32DIE4==info->devInfo.productCode)
            {
                diBitOffset=16;
                doBitOffset=16;
                diSize = 32;
                doSize = 0;
                aiSizeOut=0;
                aoSizeOut=0;
                encoderSizeOut=0;
                controlSizeOut=0;
                statusSizeOut=0;
                return 1;
            }
            else if(D_VENDOR_ID_LeiSai_IO_EM32DOE4==info->devInfo.productCode)
            {
                diBitOffset=16;
                doBitOffset=16;
                diSize = 0;
                doSize = 32;
                aiSizeOut=0;
                aoSizeOut=0;
                encoderSizeOut=0;
                controlSizeOut=0;
                statusSizeOut=0;
                return 1;
            }
            else
            {
                qDebug()<<"error,,,,D_VENDOR_ID_LeiSai_IO unknow devInfo.productCode"<<info->devInfo.productCode;
                return -1;
            }

            break;
        }
        case D_VENDOR_ID_BURKMORE_IO:
        {
            qDebug()<<"error,,,,D_VENDOR_ID_BURKMORE_IO unknow devInfo.productCode"<<info->devInfo.productCode;
            return -1;

//                  diBitOffset=16;
//                  doBitOffset=16;

            break;
        }
    case D_VENDOR_ID_SHANGHAI_XINGYANG:
    {
        if(D_VENDOR_ID_SHANGHAI_XINGYANG_ECATIOR2==info->devInfo.productCode)
        {
            diBitOffset=16;
            doBitOffset=16;
            diSize = 16;
            doSize = 16;
            aiSizeOut=2;
            aoSizeOut=2;
            encoderSizeOut=1;
            return 1;
        }
        else if(D_VENDOR_ID_SHANGHAI_XINGYANG_SMARTIOR1==info->devInfo.productCode)
        {
            diBitOffset=16;
            doBitOffset=16;
            diSize = 16;
            doSize = 16;
            aiSizeOut=0;
            aoSizeOut=0;
            encoderSizeOut=0;
            statusSizeOut=1;
            return 1;
        }
        else
        {
            qDebug()<<"error,,,,D_VENDOR_ID_SHANGHAI_XINGYANG unknow devInfo.productCode"<<info->devInfo.productCode;
            return -1;
        }

        break;
    }
    case D_VENDOR_ID_BECKHOFF:
    {
        if(D_VENDOR_ID_BECKHOFF_IO_EL3054==info->devInfo.productCode
                ||D_VENDOR_ID_BECKHOFF_IO_EL3064==info->devInfo.productCode)
        {
            diBitOffset=16;
            doBitOffset=16;
            diSize = 0;
            doSize = 0;
            aiSizeOut=4;
            aoSizeOut=0;
            encoderSizeOut=0;
            return 1;
        }
        if(D_VENDOR_ID_BECKHOFF_IO_EL4024==info->devInfo.productCode)
        {
            diBitOffset=16;
            doBitOffset=16;
            diSize = 0;
            doSize = 0;
            aiSizeOut=0;
            aoSizeOut=4;
            encoderSizeOut=0;
            return 1;
        }
        else
        {
            return getIoModuleDiDoSize_default(info, diSize, diBitOffset,doSize, doBitOffset,
                                               aiSizeOut, aoSizeOut, encoderSizeOut,
                                               controlSizeOut, statusSizeOut);
//            qDebug()<<"error,,,,D_VENDOR_ID_BECKHOFF unknow devInfo.productCode"<<info->devInfo.productCode;
//            return -1;
        }

        break;
    }
    case D_VENDOR_ID_TECHSERVO_IO:
    {
        if(D_VENDOR_ID_TECHSERVO_IO_8000==info->devInfo.productCode)
        {
            diBitOffset=1;
            doBitOffset=1;
            diSize = 8;
            doSize = 8;
//            diSize = 0;
//            doSize = 0;
            aiSizeOut=8;
//            aiSizeOut=0;
            aoSizeOut=0;
            encoderSizeOut=0;
            return 1;
        }
        else
        {
            qDebug()<<"error,,,,D_VENDOR_ID_TECHSERVO_IO unknow devInfo.productCode"<<info->devInfo.productCode;
            return -1;
        }

        break;
    }

    case D_VENDOR_ID_TECHSERVO_C48IO:
    {
        if(D_VENDOR_ID_TECHSERVO_IO_80000800==info->devInfo.productCode)
        {
            diBitOffset=16;
            doBitOffset=16;
            diSize = 16;
            doSize = 16;
//            diSize = 0;
//            doSize = 0;
            aiSizeOut=8;
//            aiSizeOut=0;
            aoSizeOut=1;
            encoderSizeOut=0;
            return 1;
        }
        else
        {
            qDebug()<<"error,,,,D_VENDOR_ID_TECHSERVO_IO_80000800 unknow devInfo.productCode"<<info->devInfo.productCode;
            return -1;
        }

        break;
    }

    default:
    {
        qDebug()<<"error,,,, getIoModuleDiDoSize unknow devInfo.productCode"<<info->devInfo.productCode;
        return -1;
    }

    }


    return 1;
}

int EcatMasterIgh::getIoModuleDiDoSize_default(S_EcatDevInfo *info, int &diSize,
                                               int &diBitOffset, int &doSize, int &doBitOffset,
                                               int &aiSizeOut, int &aoSizeOut, int &encoderSizeOut,
                                               int &controlSizeOut, int &statusSizeOut)
{
    diSize = 0;
    doSize = 0;
    aiSizeOut=0;
    aoSizeOut=0;
    encoderSizeOut=0;
    controlSizeOut=0;
    statusSizeOut=0;

    diBitOffset=1;
    doBitOffset=1;
    for(int j=0;j<info->objConfig.ec_syncs.size();j++)
    {
        if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_INPUT )
        {
            for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
            {
                for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                {
                     diSize+=diBitOffset;
                }
            }
        }
        else if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_OUTPUT )
        {
            for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
            {
                for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                {
                    doSize+=doBitOffset;
                }
            }
        }
    }
    return 1;
}

int EcatMasterIgh::assignPdoDomainOffset(int nd, S_EcatDevInfo* info, int diBitOffset,
                                         int doBitOffset,EcatIo* io)
{
    //j k n(kn也是从０开始）
    //配置不对会导致coredump
    int diCounter = 0;
    int doCounter = 0;
    int aiCounter = 0;
    int aoCounter = 0;
    int encoderCounter=0;
    int controlCounter=0;
    int statusCounter=0;
    switch( info->devInfo.vendorId )
    {
    case D_VENDOR_ID_YODA:
    {
        assignPdoDomainOffset_default(nd,info,diBitOffset,doBitOffset,io);
        break;
    }
        case D_VENDOR_ID_LeiSai_IO:
        {
        if(D_VENDOR_ID_LeiSai_IO_EM06AXE1==info->devInfo.productCode)
        {
            for(int j=0;j<info->objConfig.ec_syncs.size();j++)
            {
                if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_INPUT )
                {
                    for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                    {
                        for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                        {

                            pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                            pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                            pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                            pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                            pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                            pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                            if(3==j && 0<=k && 3>=k)
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].bit_offset );
                                aiCounter++;
                            }
                            else
                            {//ＰＤＯ都必须分配bit_position,否则内存错误崩溃
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioStatus[statusCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioStatus[statusCounter].bit_offset );
                                statusCounter++;
                            }

                            currentEntryRegIndex++;
                            domainOffKeep_noUsed +=  info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                        }
                    }
                }
                else if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_OUTPUT )
                {
                    for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                    {
                        for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                        {
                            pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                            pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                            pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                            pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                            pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                            pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                            if(2==j &&  0<=k && 1>=k)
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioAo[aoCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioAo[aoCounter].bit_offset );
                                aoCounter++;
                            }
                            else
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioControlWorld[controlCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioControlWorld[controlCounter].bit_offset );
                                controlCounter++;
                            }

                            currentEntryRegIndex++;
                            domainOffKeep_noUsed += info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                        }
                    }
                }
            }
            return 1;
        }
        else if(D_VENDOR_ID_LeiSai_IO_EM32DXE1==info->devInfo.productCode)
        {
            assignPdoDomainOffset_default(nd,info,diBitOffset,doBitOffset,io);
        }
        else if(D_VENDOR_ID_LeiSai_IO_EM32DXE4==info->devInfo.productCode)
        {
            assignPdoDomainOffset_default(nd,info,diBitOffset,doBitOffset,io);
        }
        else if(D_VENDOR_ID_LeiSai_IO_EM32DIE4==info->devInfo.productCode)
        {
            assignPdoDomainOffset_default(nd,info,diBitOffset,doBitOffset,io);
        }
        else if(D_VENDOR_ID_LeiSai_IO_EM32DOE4==info->devInfo.productCode)
        {
            assignPdoDomainOffset_default(nd,info,diBitOffset,doBitOffset,io);
        }
        else
        {
            qDebug()<<"*****error:assignPdoDomainOffset productCode "<<info->devInfo.productCode;
            return -1;
        }

            break;
        }

    case D_VENDOR_ID_SHANGHAI_XINGYANG:
    {
        if(D_VENDOR_ID_SHANGHAI_XINGYANG_ECATIOR2==info->devInfo.productCode)
        {
            for(int j=0;j<info->objConfig.ec_syncs.size();j++)
            {
                if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_INPUT )
                {
                    for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                    {
                        for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                        {

                            pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                            pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                            pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                            pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                            pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                            pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                            if(3==j && 0==k && 0==n)
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioDi[diCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioDi[diCounter].bit_offset );
                            }
                            else if(3==j && 0==k && 1==n)
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioEncoder[encoderCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioEncoder[encoderCounter].bit_offset );
                            }
                            else if(3==j && 1==k )
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].bit_offset );
                                aiCounter++;
                            }


                            currentEntryRegIndex++;
                            domainOffKeep_noUsed +=  info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                        }
                    }
                }
                else if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_OUTPUT )
                {
                    for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                    {
                        for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                        {
                            pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                            pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                            pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                            pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                            pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                            pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                            if(2==j && 0==k && 0==n)
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioDo[doCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioDo[doCounter].bit_offset );
                            }
                            else
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioAo[aoCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioAo[aoCounter].bit_offset );
                                aoCounter++;
                            }

                            currentEntryRegIndex++;
                            domainOffKeep_noUsed += info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                        }
                    }
                }
            }
            return 1;
        }
        else if(D_VENDOR_ID_SHANGHAI_XINGYANG_SMARTIOR1==info->devInfo.productCode)
        {
            for(int j=0;j<info->objConfig.ec_syncs.size();j++)
            {
                if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_INPUT )
                {
                    for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                    {
                        for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                        {

                            pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                            pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                            pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                            pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                            pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                            pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
//                            if(1==j && 0==k && 0==n)//自定义pdo
                            if(3==j && 0==k && 0==n)
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioDi[diCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioDi[diCounter].bit_offset );
                            }
                            else
                            {//ＰＤＯ都必须分配bit_position,否则内存错误崩溃
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioStatus[0].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioStatus[0].bit_offset );
//                                statusCounter++;
                                qDebug()<<"uuuuuuuuuknow EC_DIR_INPUT jkn"<<j<<k<<n;
                            }


                            currentEntryRegIndex++;
                            domainOffKeep_noUsed +=  info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                        }
                    }
                }
                else if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_OUTPUT )
                {
                    for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                    {
                        for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                        {
                            pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                            pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                            pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                            pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                            pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                            pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
//                            if(0==j && 0==k && 0==n)//自定义pdo
                            if(2==j && 0==k && 0==n)
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioDo[doCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioDo[doCounter].bit_offset );
                            }
                            else
                            {//ＰＤＯ都必须分配bit_position,否则内存错误崩溃
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioStatus[0].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioStatus[0].bit_offset );
//                                statusCounter++;
                                 qDebug()<<"uuuuuuuuuknow EC_DIR_OUTPUT jkn"<<j<<k<<n;
                            }


                            currentEntryRegIndex++;
                            domainOffKeep_noUsed += info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                        }
                    }
                }
            }
            qDebug()<<"D_VENDOR_ID_SHANGHAI_XINGYANG_SMARTIOR1";
            return 1;
        }

        else
        {
            assignPdoDomainOffset_default(nd,info,diBitOffset,doBitOffset,io);
        }
        break;
    }
    case D_VENDOR_ID_TECHSERVO_IO:
    {
        if(D_VENDOR_ID_TECHSERVO_IO_8000==info->devInfo.productCode)
        {
            for(int j=0;j<info->objConfig.ec_syncs.size();j++)
            {
                if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_INPUT )
                {
                    for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                    {
                        for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                        {
                            //j sync号，k pdo号， n entry号
                            pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                            pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                            pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                            pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                            pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                            pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                            if(3==j && 0==k )//1==k
                            {
                                //di
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioDi[diCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioDi[diCounter].bit_offset );
                                diCounter+=diBitOffset;
                            }
                            else if(3==j && 1==k )//2==k
                            {
                                //ai
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].bit_offset );
                                aiCounter++;
                            }


                            currentEntryRegIndex++;
                            domainOffKeep_noUsed +=  info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                        }
                    }
                }
                else if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_OUTPUT )
                {
                    for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                    {
                        for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                        {
                            //j sync号，k pdo号， n entry号
                            pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                            pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                            pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                            pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                            pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                            pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                            if(2==j && 0==k )
                            {
                                //do
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioDo[doCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioDo[doCounter].bit_offset );
                                doCounter+=doBitOffset;
                            }

                            currentEntryRegIndex++;
                            domainOffKeep_noUsed += info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                        }
                    }
                }
            }
            return 1;
        }
        else
        {
            assignPdoDomainOffset_default(nd,info,diBitOffset,doBitOffset,io);
        }
        break;
    }
    case D_VENDOR_ID_TECHSERVO_C48IO:
    {
        if(D_VENDOR_ID_TECHSERVO_IO_80000800==info->devInfo.productCode)
        {
            for(int j=0;j<info->objConfig.ec_syncs.size();j++)
            {
                if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_INPUT )
                {
                    for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                    {
                        for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                        {
                            //j sync号，k 从内部0开始，pdo号， n entry号
                            pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                            pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                            pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                            pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                            pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                            pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                            if(3==j && 0==k )//k从0开始
                            {
                                //di
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioDi[diCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioDi[diCounter].bit_offset );
                                diCounter+=diBitOffset;
                            }
                            else if(3==j && 1==k )//k从0开始
                            {
                                //ai
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].bit_offset );
                                aiCounter++;
                            }


                            currentEntryRegIndex++;
                            domainOffKeep_noUsed +=  info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                        }
                    }
                }
                else if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_OUTPUT )
                {
                    for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                    {
                        for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                        {
                            //j sync号，k pdo号， n entry号
                            pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                            pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                            pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                            pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                            pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                            pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                            if(2==j && 0==k )//k从0开始
                            {
                                //do
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioDo[doCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioDo[doCounter].bit_offset );
                                doCounter+=doBitOffset;
                            }
                            else if(2==j && 1==k )//k从0开始
                            {
                                pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioAo[aoCounter].byte_offset );
                                pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioAo[aoCounter].bit_offset );
                                aoCounter++;
                            }

                            currentEntryRegIndex++;
                            domainOffKeep_noUsed += info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                        }
                    }
                }
            }
            return 1;
        }
        else
        {
            assignPdoDomainOffset_default(nd,info,diBitOffset,doBitOffset,io);
        }
        break;
    }

    case D_VENDOR_ID_BECKHOFF:
    {
    if(D_VENDOR_ID_BECKHOFF_IO_EL3054==info->devInfo.productCode
            ||D_VENDOR_ID_BECKHOFF_IO_EL3064==info->devInfo.productCode)
    {
        for(int j=0;j<info->objConfig.ec_syncs.size();j++)
        {
            if( 3==j )
            {
                for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                {
                    for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                    {

                        pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                        pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                        pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                        pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                        pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                        pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
//                        if(9==n)
//                        {
                            pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].byte_offset );
                            pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].bit_offset );
                            aiCounter++;
//                        }
//                        else
//                        {//ＰＤＯ都必须分配bit_position,否则内存错误崩溃
//                            pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].byte_offset_others[n] );
//                            pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioAi[aiCounter].bit_offset_others[n] );
//                            statusCounter++;
//                        }

                        currentEntryRegIndex++;
                        domainOffKeep_noUsed +=  info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                    }
                }
            }

        }
        return 1;
    }
    else if (D_VENDOR_ID_BECKHOFF_IO_EL4024==info->devInfo.productCode)
    {
        for(int j=0;j<info->objConfig.ec_syncs.size();j++)
        {
            if( 2==j )
            {
                for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
                {
                    for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                    {
                        pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                        pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                        pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                        pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                        pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                        pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;

                        pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioAo[aoCounter].byte_offset );
                        pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioAo[aoCounter].bit_offset );
                        aoCounter++;

                        currentEntryRegIndex++;
                        domainOffKeep_noUsed += info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                    }
                }
            }
        }
        return 1;
    }
    else
    {
        assignPdoDomainOffset_default(nd,info,diBitOffset,doBitOffset,io);
    }

        break;
    }

    default:
        {
            assignPdoDomainOffset_default(nd,info,diBitOffset,doBitOffset,io);

        }

    }
    return 1;


}

int EcatMasterIgh::assignPdoDomainOffset_default(int nd, S_EcatDevInfo *info, int diBitOffset,
                                                 int doBitOffset, EcatIo *io)
{
    int diCounter = 0;
    int doCounter = 0;
//    int aiCounter = 0;
//    int aoCounter = 0;
//    int encoderCounter=0;
//    int controlCounter=0;
//    int statusCounter=0;

    for(int j=0;j<info->objConfig.ec_syncs.size();j++)
    {
        if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_INPUT )
        {
            for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
            {
                for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                {

                    pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                    pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                    pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                    pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                    pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                    pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                    pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioDi[diCounter].byte_offset );
                    pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioDi[diCounter].bit_offset );
                    diCounter+=diBitOffset;

                    currentEntryRegIndex++;
                    domainOffKeep_noUsed +=  info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                }
            }
        }
        else if( info->objConfig.ec_syncs.at(j).dir == EC_DIR_OUTPUT )
        {
            for(int k=0;k<info->objConfig.ec_syncs.at(j).n_pdos;k++)
            {
                for(int n=0;n<info->objConfig.ec_syncs.at(j).pdos[k].n_entries;n++)
                {
                    pdoEntryRegList[ currentEntryRegIndex ].alias = 0;// info->devInfo.alias;
                    pdoEntryRegList[ currentEntryRegIndex ].position = nd;
                    pdoEntryRegList[ currentEntryRegIndex ].vendor_id = info->devInfo.vendorId;
                    pdoEntryRegList[ currentEntryRegIndex ].product_code = info->devInfo.productCode;
                    pdoEntryRegList[ currentEntryRegIndex ].index = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].index;
                    pdoEntryRegList[ currentEntryRegIndex ].subindex = info->objConfig.ec_syncs.at(j).pdos[k].entries[n].subindex;
                    pdoEntryRegList[ currentEntryRegIndex ].offset = &( io->ethercatPdoDataOffsetInfo.ioDo[doCounter].byte_offset );
                    pdoEntryRegList[ currentEntryRegIndex ].bit_position = &( io->ethercatPdoDataOffsetInfo.ioDo[doCounter].bit_offset );
                    doCounter+=doBitOffset;
                    currentEntryRegIndex++;
                    domainOffKeep_noUsed += info->objConfig.ec_syncs.at(j).pdos[k].entries[n].bit_length;

                }
            }
        }
    }

    return 1;

}

int EcatMasterIgh::syncsConfig(ec_slave_config_t *&sc, int nd )
{
    int siz=robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs.size();
    if(0>=siz)
    {
        rt_printf( "EcatMasterIgh::syncsConfig error, slave have no syncs information.\n");
        return -1;
    }
    if( ecrt_slave_config_pdos( sc, siz,  &(robCtl->busManager->ec_devInfo[nd].objConfig.ec_syncs[0]) ) )
    {
        rt_printf( "fail to configure syncs.\n");
        slaveConfigError |= 1<<nd;
    }

#if D_USE_DC_SYNC
    //配置同步管理时钟
    if( robCtl->busManager->ec_devInfo[nd].devInfo.devType==E_EcatDev_Servo )//911MotorTest
    {
//       ecrt_slave_config_dc(sc, 0x300, cycle_ns , 0, 0, 0);//dc 开的标志一般为0x300,SHIFT TIME 一般为０，有的伺服不是。
        ecrt_slave_config_dc(sc, 0x300, cycle_ns , 440000, 0, 0);//开启 440000ns //911MotorTest
//        ecrt_slave_config_dc(sc, 0x300, cycle_ns , cycle_ns/2, 0, 0);//开启 440000
//        ecrt_slave_config_dc(sc, 0x0, cycle_ns , 0, 0, 0);//不开启ＤＣ
      //  ecrt_slave_config_dc(sc, 0x300, cycle_ns , 440000, 0, 0);//开启
        rt_printf("开启DC同步,站号: %d\n", nd);
    }
    else
    {
        ecrt_slave_config_dc(sc, 0x0, cycle_ns , 0, 0, 0);//off
        rt_printf("关闭DC同步,站号: %d\n", nd);
    }
#else
    if(robCtl->busManager->ec_devInfo[nd].devInfo.devType==E_EcatDev_Servo ){
        //ecrt_slave_config_dc(sc, 0x0, cycle_ns , 4400000, 0, 0);//关闭
        ecrt_slave_config_dc(sc, 0x0, cycle_ns , 0, 0, 0);//关闭
    }
#endif
    return 1;
}

void EcatMasterIgh::readMotorData(RobotBase* rob)
{
    if(robCtl->vrepCtl->motorSmiulationMode!=E_ECAT_VREP )
    {
        //read　real motor data
        for( int i=0;i<rob->ethercatAxis.size();i++ )
        {
            for(int channelIndex=0;channelIndex<rob->ethercatAxis.at(i)->maxChannel;channelIndex++)
            {
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetErrorCodeGet[channelIndex]!=D_OD_NOT_USED ){
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->errorCode =  EC_READ_U16(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetErrorCodeGet[channelIndex]  );
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetServoStateGet[channelIndex]!=D_OD_NOT_USED ){
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->stateWord =  EC_READ_S16(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetServoStateGet[channelIndex]  );
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetEncoderGet[channelIndex]!=D_OD_NOT_USED ){
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->actPosition =  EC_READ_S32(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetEncoderGet[channelIndex]  );
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->encoderValue = rob->ethercatAxis.at(i)->logicMotors[channelIndex]->actPosition
                            -rob->ethercatAxis.at(i)->logicMotors[channelIndex]->homeOffset;
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetSpeedGet[channelIndex]!=D_OD_NOT_USED ){
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->writeActVelocity ( EC_READ_S32(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetSpeedGet[channelIndex] ));
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetTorqueGet[channelIndex]!=D_OD_NOT_USED ){
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->actTorque =  EC_READ_S16(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetTorqueGet[channelIndex]  );
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetFollowingErrorGet[channelIndex] !=D_OD_NOT_USED ){
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->actFollowErr =  EC_READ_S32(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetFollowingErrorGet[channelIndex]  );
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetAmpModeGet[channelIndex]!=D_OD_NOT_USED ){
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->disModeOfOperation = EC_READ_U8(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetAmpModeGet[channelIndex]  );
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetMotorDiGet[channelIndex]!=D_OD_NOT_USED ){
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->digIn =  EC_READ_U32(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetMotorDiGet[channelIndex] );
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetMotorDoGet[channelIndex]!=D_OD_NOT_USED ){
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->digOut =  EC_READ_U32(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetMotorDoGet[channelIndex]  );
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetExternalFeedback[channelIndex] !=D_OD_NOT_USED ){
                    rob->ethercatAxis.at(i)->logicMotors[channelIndex]->externalFeedback =  EC_READ_S32(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetFollowingErrorGet[channelIndex]  );
                }
            }

        }



    }
    else
    {
        //read vrep motor data
        VrepObject* vob=robCtl->vobMap.value( rob->robotInfo.robotId, NULL );
        if( vob )
        {
            for( int i=0;i<rob->ethercatAxis.size();i++ ){
                rob->ethercatAxis.at(i)->logicMotors[0]->actPosition = p_powerManger->getVrepRadianToEncoder(rob->robotInfo.robotId,
                                                                                             i, vob->getPos[i] );
                rob->ethercatAxis.at(i)->logicMotors[0]->encoderValue = rob->ethercatAxis.at(i)->logicMotors[0]->actPosition
                        -rob->ethercatAxis.at(i)->logicMotors[0]->homeOffset;
                //read state
                if( (rob->ethercatAxis.at(i)->logicMotors[0]->controlWord & 0x0F) == 0x0b ){
                    rob->ethercatAxis.at(i)->logicMotors[0]->stateWord= 561 ;
                }else if( (rob->ethercatAxis.at(i)->logicMotors[0]->controlWord & 0x0F) == 0x0F ) {
                    rob->ethercatAxis.at(i)->logicMotors[0]->stateWord = 4663 ;
                }else  if( (rob->ethercatAxis.at(i)->logicMotors[0]->controlWord & 0x07) == 0x07 ){
                    rob->ethercatAxis.at(i)->logicMotors[0]->stateWord= 0x0023 ;
                }else  {
                    rob->ethercatAxis.at(i)->logicMotors[0]->stateWord= 561 ;
                }
            }
        }

    }

#if D_WRITE_SERVO_DATA_TO_FILE
            std::vector<int> record;
            record.resize( rob->axis.size() );
#endif

#if D_WRITE_SERVO_DATA_TO_FILE
            for( int i=0;i<rob->axis.size();i++ ){
                record[i]=rob->axis.at(i)->targetPosition;
            }
            static qint64 recordDataForAnalysize=-1;
            if( 1 ){
                recordDataForAnalysize++;
                dataAnalysizer->recordDataForAnalysize( record );
            }else{
                if( recordDataForAnalysize>20000  ){
                    recordDataForAnalysize=0;
                    dataAnalysizer->writeDataQueueToFile( D_TMP_SERVO_DATA_FILE );
                }
            }
#endif

}

void EcatMasterIgh::readIoData(RobotBase *rob)
{
    //不支持32bit类型的dido对象字典。
    if(robCtl->vrepCtl->ioSmiulationMode!=E_ECAT_VREP )
   {

       //read real io_module data

        for( int moduleIndex=0;moduleIndex<rob->ethercatIoModule.size();moduleIndex++ )
        {
            switch( rob->ethercatIoModule.at(moduleIndex)->vendorId )
            {
            case D_VENDOR_ID_YODA:
            {
                //short代表16个di
                for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->diCount;ioIndex++ )
                {
                    if( 0==(ioIndex&0x0f) )
                        rob->ethercatIoModule.at(moduleIndex)->p_ioDi_short[ioIndex>>4]=EC_READ_U16( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDi.at(ioIndex).byte_offset );
                }

                break;
            }

                case D_VENDOR_ID_LeiSai_IO:
                {
                    //short代表16个di
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->diCount;ioIndex++ )
                    {
                        if( 0==(ioIndex&0x0f) )
                            rob->ethercatIoModule.at(moduleIndex)->p_ioDi_short[ioIndex>>4]=EC_READ_U16( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDi.at(ioIndex).byte_offset );
                    }
                    //int代表1个ai
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->aiCount;ioIndex++ )
                    {
                        rob->ethercatIoModule.at(moduleIndex)->p_ioAi[ioIndex]=EC_READ_S32( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioAi.at(ioIndex).byte_offset );
                    }
                    //short代表1个errorcode。
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->statusCount;ioIndex++ )
                    {
                        rob->ethercatIoModule.at(moduleIndex)->p_ioStatus[ioIndex]=EC_READ_U16( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioStatus.at(ioIndex).byte_offset );
                    }
                    break;
                }
            case D_VENDOR_ID_SHANGHAI_XINGYANG:
            {
                //short代表16个di
                for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->diCount;ioIndex++ )
                {
                    if( 0==(ioIndex&0x0f) )
                        rob->ethercatIoModule.at(moduleIndex)->p_ioDi_short[ioIndex>>4]=EC_READ_U16( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDi.at(ioIndex).byte_offset );
                }
                //short代表1个ai
                for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->aiCount;ioIndex++ )
                {
                    rob->ethercatIoModule.at(moduleIndex)->p_ioAi[ioIndex]=EC_READ_U16( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioAi.at(ioIndex).byte_offset );
                }
                //int代表1个encoder
                for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->encoderCount;ioIndex++ )
                {
                    rob->ethercatIoModule.at(moduleIndex)->p_ioEncoder[ioIndex]=EC_READ_S32( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioEncoder.at(ioIndex).byte_offset );
                }
                break;
            }
            case D_VENDOR_ID_TECHSERVO_C48IO:
            {
                //short代表16个di
                for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->diCount;ioIndex++ )
                {
                    if( 0==(ioIndex&0x0f) )
                        rob->ethercatIoModule.at(moduleIndex)->p_ioDi_short[ioIndex>>4]=EC_READ_U16( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDi.at(ioIndex).byte_offset );
                }
                //short代表1个ai
                for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->aiCount;ioIndex++ )
                {
                    rob->ethercatIoModule.at(moduleIndex)->p_ioAi[ioIndex]=EC_READ_U16( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioAi.at(ioIndex).byte_offset );
                }

                break;
            }

            case D_VENDOR_ID_BURKMORE_IO:
                {
                    //short代表16个di
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->diCount;ioIndex++ )
                    {
                        if( 0==(ioIndex&0x0f) )
                            rob->ethercatIoModule.at(moduleIndex)->p_ioDi_short[ioIndex>>4]=EC_READ_U16( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDi.at(ioIndex).byte_offset );
                    }
                    break;
                }
            case D_VENDOR_ID_BECKHOFF:
            {
                //char代表８个di
                for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->diCount;ioIndex++ )
                {
                    if( 0==(ioIndex&0x07) )
                        rob->ethercatIoModule.at(moduleIndex)->p_ioDi[ioIndex>>3]=EC_READ_U8( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDi.at(ioIndex).byte_offset );
                }
                //short代表1个ai
                for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->aiCount;ioIndex++ )
                {
                    rob->ethercatIoModule.at(moduleIndex)->p_ioAi[ioIndex]=EC_READ_S16( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioAi.at(ioIndex).byte_offset );
                }
                break;
            }

                default:
                {
                    //char代表８个di
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->diCount;ioIndex++ )
                    {
                        if( 0==(ioIndex&0x07) )
                            rob->ethercatIoModule.at(moduleIndex)->p_ioDi[ioIndex>>3]=EC_READ_U8( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDi.at(ioIndex).byte_offset );
                    }
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->aiCount;ioIndex++ )
                    {
                        rob->ethercatIoModule.at(moduleIndex)->p_ioAi[ioIndex]=EC_READ_S32( domain_p + rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioAi.at(ioIndex).byte_offset );
                    }
                }
            }

        }

   }
   else
   {
       //read vrep io
       // todo
    }
}

int EcatMasterIgh::exchangeData_EncoderReceiver()
{

       if(robCtl->vrepCtl->ioSmiulationMode!=E_ECAT_VREP )
       {

           //read real io_module data

            for(int i=0;i<robCtl->busManager->encoderReceiverSize;i++)
            {
                switch( robCtl->busManager->encoderReceiverArry[i]->vendorId )
                {
                    case D_VENDOR_ID_LeiSai_IO:
                    {

                        //write
                        EC_WRITE_U16(domain_p +  robCtl->busManager->encoderReceivers[i]->domainOffset.doOutput
                                    ,robCtl->busManager->encoderReceiverArry[i]->pdoData.doOutput);
                        //write
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Encoder0_Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Encoder0_Val );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Encoder1_Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Encoder1_Val );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Encoder2_Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Encoder2_Val );

                         robCtl->busManager->encoderReceiverArry[i]->pdoData.HighSpeed_IN0=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.HighSpeed_IN0 );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc0_Finished=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc0_Finished );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc0_Encoder0Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc0_Encoder0Val );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc0_Encoder1Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc0_Encoder1Val );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc0_Encoder2Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc0_Encoder2Val );

                         robCtl->busManager->encoderReceiverArry[i]->pdoData.HighSpeed_IN1=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.HighSpeed_IN1 );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc1_Finished=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc1_Finished );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc1_Encoder0Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc1_Encoder0Val );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc1_Encoder1Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc1_Encoder1Val );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc1_Encoder2Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc1_Encoder2Val );


                         robCtl->busManager->encoderReceiverArry[i]->pdoData.HighSpeed_IN2=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.HighSpeed_IN2 );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc2_Finished=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc2_Finished );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc2_Encoder0Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc2_Encoder0Val );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc2_Encoder1Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc2_Encoder1Val );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc2_Encoder2Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc2_Encoder2Val );

                         robCtl->busManager->encoderReceiverArry[i]->pdoData.HighSpeed_IN3=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.HighSpeed_IN3 );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc3_Finished=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc3_Finished );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc3_Encoder0Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc3_Encoder0Val );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc3_Encoder1Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc3_Encoder1Val );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Ltc3_Encoder2Val=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Ltc3_Encoder2Val );

                         robCtl->busManager->encoderReceiverArry[i]->pdoData.HighSpeed_ReadOut0=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.HighSpeed_ReadOut0 );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Cmp0_FIFO_Exist=EC_READ_U16( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Cmp0_FIFO_Exist );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Cmp0_Finished_Number=EC_READ_U16( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Cmp0_Finished_Number );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Cmp0_Current_CmpData=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Cmp0_Current_CmpData );


                         robCtl->busManager->encoderReceiverArry[i]->pdoData.HighSpeed_ReadOut1=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.HighSpeed_ReadOut1 );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Cmp1_FIFO_Exist=EC_READ_U16( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Cmp1_FIFO_Exist );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Cmp1_Finished_Number=EC_READ_U16( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Cmp1_Finished_Number );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Cmp1_Current_CmpData=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Cmp1_Current_CmpData );



                         robCtl->busManager->encoderReceiverArry[i]->pdoData.HighSpeed_ReadOut2=EC_READ_U8( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.HighSpeed_ReadOut2 );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Cmp2_FIFO_Exist=EC_READ_U16( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Cmp2_FIFO_Exist );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Cmp2_Finished_Number=EC_READ_U16( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Cmp2_Finished_Number );
                         robCtl->busManager->encoderReceiverArry[i]->pdoData.Cmp2_Current_CmpData=EC_READ_S32( domain_p +
                                robCtl->busManager->encoderReceiverArry[i]->domainOffset.Cmp2_Current_CmpData );

                           //溢出处理
//                         robCtl->busManager->encoderReceiverArry[i]->checkMultiVerse();

                        break;
                    }
                    case D_VENDOR_ID_BURKMORE_IO:
                    {

                        break;
                    }
                    default:
                    {

                    }
                }

            }


       }
        else
        {
            //read vrep io
            // todo
         }

       return 1;

}

int EcatMasterIgh::initialSdo_EncoderReceiver(int &aliasOut,int &sdoIndexOut)
{
    if(robCtl->vrepCtl->ioSmiulationMode==E_ECAT_VREP )
    {
        return 1;
    }

    for(int i=0;i<robCtl->busManager->encoderReceiverSize;i++)
    {
        QVector<SdoConfig> tmpsdoConfigList=robCtl->busManager->encoderReceiverArry[i]->sdoConfigList;
        int nodeId;
        if(true!=robCtl->busManager->getEthercatNodeIdByAlias(robCtl->busManager->encoderReceiverArry[i]->alias,
                                                              nodeId))
        {
            aliasOut=robCtl->busManager->encoderReceiverArry[i]->alias;
            sdoIndexOut=-1;
            return -1;
        }

        for(int j=0;j<tmpsdoConfigList.size();j++)
        {
            int tryCount=100;
            bool isSucess=false;
            while(tryCount>0)
            {
                if(1==sdoDownload( nodeId, tmpsdoConfigList[j].index, tmpsdoConfigList[j].subindex,
                                   tmpsdoConfigList[j].value ,tmpsdoConfigList[j].byteLength ))
                {
                    isSucess=true;
                    break;
                }
                qDebug()<<"initialSdo_EncoderReceiver failed!!! alias"<<robCtl->busManager->ec_motors[i]->alias
                       <<"tryCount"<<tryCount;
                tryCount--;
            }
            if(false==isSucess)
            {
                aliasOut=robCtl->busManager->ec_motors[i]->alias;
                sdoIndexOut=j;
                return -100-j;
            }

        }

    }
    return 1;

}

void EcatMasterIgh::writeMotorData(RobotBase *rob)
{

    if(robCtl->vrepCtl->motorSmiulationMode!=E_ECAT_VREP )
    {
        //write　real motor data
        for( int i=0;i<rob->ethercatAxis.size();i++ )
        {
            for(int channelIndex=0;channelIndex<rob->ethercatAxis.at(i)->maxChannel;channelIndex++)
            {
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetControlWorldSet[channelIndex]!=D_OD_NOT_USED ){
                    EC_WRITE_U16(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetControlWorldSet[channelIndex]
                                 ,rob->ethercatAxis.at(i)->logicMotors[channelIndex]->controlWord);
    //                qDebug()<<"i"<<i<<"controlWord"<<rob->ethercatAxis.at(i)->controlWord;
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetAmpModeSet[channelIndex]!=D_OD_NOT_USED ){
                    EC_WRITE_U8(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetAmpModeSet[channelIndex],
                                rob->ethercatAxis.at(i)->logicMotors[channelIndex]->modeOfOperation);
    //                qDebug()<<"i"<<i<<"modeOfOperation"<<rob->ethercatAxis.at(i)->modeOfOperation;
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetTargetPosSet[channelIndex]!=D_OD_NOT_USED ){
                    EC_WRITE_S32(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetTargetPosSet[channelIndex]
                                 ,rob->ethercatAxis.at(i)->logicMotors[channelIndex]->targetPosition
                                 +rob->ethercatAxis.at(i)->logicMotors[channelIndex]->homeOffset);
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetTargetTorqueSet[channelIndex]!=D_OD_NOT_USED ){
                    EC_WRITE_S16(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetTargetTorqueSet[channelIndex]
                                 ,rob->ethercatAxis.at(i)->logicMotors[channelIndex]->targetTorque );
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetTargetSpeedSet[channelIndex]!=D_OD_NOT_USED ){
                    EC_WRITE_S32(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetTargetSpeedSet[channelIndex]
                                 ,rob->ethercatAxis.at(i)->logicMotors[channelIndex]->targetVelocity );
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetTorqueOffSet[channelIndex]!=D_OD_NOT_USED ){
                    EC_WRITE_S16(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetTorqueOffSet[channelIndex]
                                 ,rob->ethercatAxis.at(i)->logicMotors[channelIndex]->torqueOffset);
                }
                if( rob->ethercatAxis.at(i)->pdoDomainOffset.offsetSpeedOffSet[channelIndex]!=D_OD_NOT_USED ){
                    EC_WRITE_S32(domain_p + rob->ethercatAxis.at(i)->pdoDomainOffset.offsetSpeedOffSet[channelIndex]
                                 ,rob->ethercatAxis.at(i)->logicMotors[channelIndex]->velocityOffset );
                }
            }

        }
    }


    if( robCtl->vrepCtl->motorSmiulationMode!=E_ECAT_REAL )
    {
        if( rob->get_data_flag ){
            //write vrep motor
            VrepObject* vob=robCtl->vobMap.value( rob->robotInfo.robotId, NULL );
            if( vob && p_powerManger )
            {
                for( int i=0;i<rob->ethercatAxis.size();i++ ){
                    vob->setPos[i] = p_powerManger
                            ->getVrepEncoderToRadian( rob->robotInfo.robotId,
                                      i , rob->ethercatAxis.at(i)->logicMotors[0]->targetPosition
                            +rob->ethercatAxis.at(i)->logicMotors[0]->homeOffset );
                }
                vob->setChanged=true;
            }
        }
    }
}

void EcatMasterIgh::writeIoData(RobotBase *rob)
{
//不支持32bit类型的dido对象字典。
    if(robCtl->vrepCtl->ioSmiulationMode!=E_ECAT_VREP )
    {

        //  write io_module data
        for( int moduleIndex=0;moduleIndex<rob->ethercatIoModule.size();moduleIndex++ )
        {
            rob->ethercatIoModule.at(moduleIndex)->updateEthercatDo();
            switch( rob->ethercatIoModule.at(moduleIndex)->vendorId )
            {
            //short代表16个do
                case D_VENDOR_ID_YODA:
                {
                    //short代表16个do
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->doCount;ioIndex++ )
                    {

                        if( 0==(ioIndex&0x0f) )
                            EC_WRITE_U16(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDo.at(ioIndex).byte_offset
                                        ,rob->ethercatIoModule.at(moduleIndex)->p_ioDo_short[ioIndex>>4] );

                    }

                    break;
                }
            //short代表16个do
                case D_VENDOR_ID_LeiSai_IO:
                {
                    //short代表16个do
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->doCount;ioIndex++ )
                    {

                        if( 0==(ioIndex&0x0f) )
                            EC_WRITE_U16(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDo.at(ioIndex).byte_offset
                                        ,rob->ethercatIoModule.at(moduleIndex)->p_ioDo_short[ioIndex>>4] );

                    }
                    //int 代表１个AOUT
                    for( int j=0;j<rob->ethercatIoModule.at(moduleIndex)->aoCount;j++ )
                    {
                        EC_WRITE_S32(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioAo.at(j).byte_offset
                                     ,rob->ethercatIoModule.at(moduleIndex)->p_ioAo[j] );
                    }
                    //short 代表１个控制字
                    for( int j=0;j<rob->ethercatIoModule.at(moduleIndex)->controlCount;j++ )
                    {
                        EC_WRITE_U16(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioControlWorld.at(j).byte_offset
                                     ,rob->ethercatIoModule.at(moduleIndex)->p_ioControlWorld[j] );
                    }


                    break;
                }
            //short代表16个do
            case D_VENDOR_ID_SHANGHAI_XINGYANG:
            {
                for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->doCount;ioIndex++ )
                {
                    if( 0==(ioIndex&0x0f) )
                        EC_WRITE_U16(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDo.at(ioIndex).byte_offset
                                    ,rob->ethercatIoModule.at(moduleIndex)->p_ioDo_short[ioIndex>>4] );
                }

                for( int j=0;j<rob->ethercatIoModule.at(moduleIndex)->aoCount;j++ )
                {
                    EC_WRITE_S16(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioAo.at(j).byte_offset
                                 ,rob->ethercatIoModule.at(moduleIndex)->p_ioAo[j] );
                }


                break;
            }
                //short代表16个do
                case D_VENDOR_ID_TECHSERVO_C48IO:
                {
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->doCount;ioIndex++ )
                    {
                        if( 0==(ioIndex&0x0f) )
                            EC_WRITE_U16(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDo.at(ioIndex).byte_offset
                                        ,rob->ethercatIoModule.at(moduleIndex)->p_ioDo_short[ioIndex>>4] );
                    }

                    for( int j=0;j<rob->ethercatIoModule.at(moduleIndex)->aoCount;j++ )
                    {
                        EC_WRITE_S16(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioAo.at(j).byte_offset
                                     ,rob->ethercatIoModule.at(moduleIndex)->p_ioAo[j] );
                    }


                    break;
                }
                case D_VENDOR_ID_BURKMORE_IO:
                {
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->doCount;ioIndex++ )
                    {
                        if( 0==(ioIndex&0x0f) )
                            EC_WRITE_U16(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDo.at(ioIndex).byte_offset
                                        ,rob->ethercatIoModule.at(moduleIndex)->p_ioDo_short[ioIndex>>4] );
                    }


                    break;
                }
                //short代表16个do
                case D_VENDOR_ID_BECKHOFF:
                {
                    //char代表1个do
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->doCount;ioIndex++ )
                    {
                        if( 0==(ioIndex&0x07) )
                            EC_WRITE_U8(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDo.at(ioIndex).byte_offset
                                        ,rob->ethercatIoModule.at(moduleIndex)->p_ioDo[ioIndex>>3] );
                    }
                    //short 代表１个AOUT
                    for( int j=0;j<rob->ethercatIoModule.at(moduleIndex)->aoCount;j++ )
                    {
                        EC_WRITE_S16(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioAo.at(j).byte_offset
                                     ,rob->ethercatIoModule.at(moduleIndex)->p_ioAo[j] );
                    }



                    break;
                }

                default:
                {
                    //char代表1个do
                    for( int ioIndex=0;ioIndex<rob->ethercatIoModule.at(moduleIndex)->doCount;ioIndex++ )
                    {
                        if( 0==(ioIndex&0x07) )
                            EC_WRITE_U8(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioDo.at(ioIndex).byte_offset
                                        ,rob->ethercatIoModule.at(moduleIndex)->p_ioDo[ioIndex>>3] );
                    }
                    //int 代表1个ao
                    for( int j=0;j<rob->ethercatIoModule.at(moduleIndex)->aoCount;j++ )
                    {
                        EC_WRITE_U32(domain_p +  rob->ethercatIoModule.at(moduleIndex)->ethercatPdoDataOffsetInfo.ioAo.at(j).byte_offset
                                     ,rob->ethercatIoModule.at(moduleIndex)->p_ioAo[j] );
                    }
                }

            }

        }


    }


    if( robCtl->vrepCtl->ioSmiulationMode!=E_ECAT_REAL )
    {
        //write vrep io
        //todo
    }
}

void EcatMasterIgh::writeTestData(RobotBase *rob)
{


    static int tCount=0;
    tCount++;
    if(tCount>10000000/cycle_us){
        tCount=0;

        //printNowTime();

        qDebug()<<"========================================";
        for( int j=0;j<rob->ethercatAxis.size();j++ )//todo
        {
//            printf("%d:MD:%d,ST:%d, ctl:%d,err:%d, encode:%d,%d,%d,%d,%d,%d,%d, %d\n",
//                   j,
//                   rob->ethercatAxis.at(j)->modeOfOperation,
//                   rob->ethercatAxis.at(j)->stateWord,
//                   rob->ethercatAxis.at(j)->controlWord,
//                   rob->ethercatAxis.at(j)->errorCode,
//                   rob->ethercatAxis.at(j)->encoderValue,
//                   rob->ethercatAxis.at(j)->actPosition,
//                   rob->ethercatAxis.at(j)->homeOffset,
//                   rob->ethercatAxis.at(j)->targetPosition,
//                   isSlavesOp,
//                   robCtl->vrepCtl->motorSmiulationMode,
//                   rob->ethercatAxis.at(j)->actVelocity,
//                   rob->ethercatAxis.at(j)->targetVelocity
//                   );
        }
        for( int j=0;j<rob->ethercatIoModule.size();j++ )
        {
            printf("%d:di=%d,do=%d,ai=%d,ao=%d \n",
                   j,
                   rob->ethercatIoModule.at(j)->diCount,
                   rob->ethercatIoModule.at(j)->doCount,
                   rob->ethercatIoModule.at(j)->aiCount,
                   rob->ethercatIoModule.at(j)->aoCount
                   );
        }
    }

}

int EcatMasterIgh::downloadServoSdoConfig(int &aliasOut,int &sdoIndexOut)
{
    if(robCtl->vrepCtl->ioSmiulationMode==E_ECAT_VREP )
    {
        return 1;
    }

    for(int i=0;i<robCtl->busManager->ec_motorSize;i++)
    {
        QVector<SdoConfig> tmpsdoConfigList;
        robCtl->busManager->ec_motors[i]->getSdoList(tmpsdoConfigList);
        int nodeId;
        if(true!=robCtl->busManager->getEthercatNodeIdByAlias
                (robCtl->busManager->ec_motors[i]->alias,nodeId))
        {
            aliasOut=robCtl->busManager->ec_motors[i]->alias;
            sdoIndexOut=-1;
            return -1;
        }

        //允许尝试10次。
        for(int j=0;j<tmpsdoConfigList.size();j++)
        {
            int tryCount=100;
            bool isSucess=false;
            while(tryCount>0)
            {
                if(1==sdoDownload( nodeId, tmpsdoConfigList[j].index, tmpsdoConfigList[j].subindex,
                             tmpsdoConfigList[j].value ,tmpsdoConfigList[j].byteLength ))
                {
                    isSucess=true;
                    break;
                }
                qDebug()<<"downloadServoSdoConfig failed!!! alias"<<robCtl->busManager->ec_motors[i]->alias
                       <<"tryCount"<<tryCount;
                tryCount--;
            }
            if(false==isSucess)
            {
                aliasOut=robCtl->busManager->ec_motors[i]->alias;
                sdoIndexOut=j;
                return -100-j;
            }
        }

    }
    return 1;
}

int EcatMasterIgh::downloadIodeviceSdoConfig(int &aliasOut, int &sdoIndexOut)
{
    if(robCtl->vrepCtl->ioSmiulationMode==E_ECAT_VREP )
    {
        return 1;
    }

    for(int i=0;i<robCtl->busManager->ec_ioModuleSize;i++)
    {
        QVector<SdoConfig> tmpsdoConfigList;
        robCtl->busManager->ec_ioModule[i]->getSdoList(tmpsdoConfigList);
        int nodeId;
        if(true!=robCtl->busManager->getEthercatNodeIdByAlias
                (robCtl->busManager->ec_ioModule[i]->alias,nodeId))
        {
            aliasOut=robCtl->busManager->ec_ioModule[i]->alias;
            sdoIndexOut=-1;
            return -1;
        }

        //允许尝试10次。
        for(int j=0;j<tmpsdoConfigList.size();j++)
        {
            int tryCount=100;
            bool isSucess=false;
            while(tryCount>0)
            {
                if(1==sdoDownload( nodeId, tmpsdoConfigList[j].index, tmpsdoConfigList[j].subindex,
                             tmpsdoConfigList[j].value ,tmpsdoConfigList[j].byteLength ))
                {
                    isSucess=true;
                    break;
                }
                qDebug()<<"downloadIoSdoConfig failed!!! alias"<<robCtl->busManager->ec_ioModule[i]->alias
                       <<"tryCount"<<tryCount;
                tryCount--;
            }
            if(false==isSucess)
            {
                aliasOut=robCtl->busManager->ec_ioModule[i]->alias;
                sdoIndexOut=j;
                return -100-j;
            }
        }

    }
    return 1;
}

void EcatMasterIgh::updateDomainData()
{
    exchangeData_EncoderReceiver();
    RobotBase* rob;
    foreach( rob, robCtl->robotsMap )
    {
        if( !rob ){
            continue;
        }
        if( !rob->isLinkOk )
            continue;

        if(isSlavesOp)
        {
            readMotorData(rob);
            readIoData(rob);
            rob->test_demo();//测试用

            rob->updateEthercatIoData();//io数据映射交换
            TimeTool::getInstance()->recordInTime(timer_id_measure[D_TIME_MATH]);
            setServoData(rob);//算法数据交换
            TimeTool::getInstance()->recordOutTime(timer_id_measure[D_TIME_MATH]);

            rob->checkEthercatDeviceError();
            for( int i=0;i<rob->ethercatAxis.size();i++ )
            {
                rob->ethercatAxis.at(i)->updateMotorState();
            }

            writeMotorData(rob);
            writeIoData(rob);

        }
    }

    //writeTestData(rob);

}

int EcatMasterIgh::rt_check_slaves_state(bool isInitialState)
{
    bool isok=true;
    for( int i = 0; i < robCtl->busManager->devCount(); i++ )
    {
        if( isSlaveInOp[i] )
        {
            if(isInitialState)
            {
                continue;
            }

        }
        else
        {
            isok=false;
        }
        ec_slave_config_state_t slave_state;
        ecrt_slave_config_state( slave_sc[i], &slave_state ) ;
        unsigned int al_state= slave_state.al_state;//
        int __error_flag=0;
        slavesAl[i]=slave_state.al_state;
        if( al_state &0x0E && al_state &0x01 )
        {
            qDebug()<<slave_state.al_state << "有错误标志,slave have error flag";
            if( --error_flag_count <1 )
            {
                __error_flag=1;
            }
            addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9047, -1,i,al_state);
        }
        if(8!=al_state && true==isInitialedOk)
        {
            qDebug()<<"slave is not in op,nodeid="<<i;
            addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9046, -1,i,al_state);
        }

        char* errstr="";
        if( __error_flag )
        {
            errstr=" + ERROR";
            error_flag=1;
        }
        switch(  al_state &0x0E )
        {
            case 1:
                rt_printf( "Slave %d AL: INIT%s\n" , i, errstr );
                break;
            case 2:
                if( __error_flag )
                    rt_printf( "Slave %d AL: PREOP%s\n " , i, errstr );
                break;
            case 4:
                rt_printf( "Slave %d AL: SAFEOP%s\n", i , errstr );
                break;
            case 8:
                rt_printf( "Slave %d AL: OP%s\n" , i, errstr );
                isSlaveInOp[i] = true;
                break;
            default:
                rt_printf( "Slave %d AL: ???%s\n" , i, errstr );
                break;
        }
        if( __error_flag )
        {
            return -1;
        }
    }

    return isok?0:1;
}

int EcatMasterIgh::rt_check_master_state()
{
    if(NULL==master)
    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9073, -1,0);
        setMasterState(eMasterErr_LOCK);
        return 0;
    }
    ec_master_state_t ms;
    ecrt_master_state(master, &ms);

    if (ms.slaves_responding != robCtl->busManager->devCount()
            && true==isInitialedOk)
    {
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9043, -1,
               ms.slaves_responding, robCtl->busManager->devCount() );
        rt_printf("error:  %u slave(s).\n", ms.slaves_responding);
        if(0==ms.slaves_responding)
        {
            addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9039, -1  );
        }
        setMasterState(eMasterErr_LOCK);
    }

    if (ms.al_states != 8 && true==isInitialedOk)
    {
        isSlavesOp=false;
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9044, -1 ,ms.al_states );
        rt_printf("error:  Master AL states: 0x%02X.,ms.link_up %d\n", ms.al_states,ms.link_up);

        rt_check_slaves_state(false);//检查从站状态
        stage=E_ETHERCAT_STAGE_CHECK_SLAVES_OK;
    }


    if( false==ms.link_up )
    {
        rt_printf("error:  9039 ethercat 设备没有响应, 请检查网卡或网络状态！\n");
        addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9039, -1  );
        setMasterState(eMasterErr_LOCK);
//        resetMasterStatus();可以被恢复

        return -1;
    }

    master_state = ms;
    return 0;
}

//int EcatMasterIgh::rt_check_domain_state()
//{
//    ec_domain_state_t ds = {};

//    ecrt_domain_state(domain, &ds);

//    if (ds.working_counter != domain_state.working_counter) {
//        rt_printf("Domain1: WC %u.\n", ds.working_counter);
//    }

//    if (ds.wc_state != domain_state.wc_state) {
//        rt_printf("Domain1: State %u.\n", ds.wc_state);
//    }



//    domain_state = ds;

//    return 1;

//}

int EcatMasterIgh::rt_check_domain_state()
{
    int ret = 0;//ok
    ec_domain_state_t ds;
    //  memset( &ds, 0, sizeof( ec_domain_state_t ) );
    ecrt_domain_state(domain, &ds);

    // domainStateRrror=0;
    if( isSlavesOp )
    {
//        // ，TCR7容易断线，临时注释ＷＫＣ消息报错.WKC hualei 华磊
//        if (ds.working_counter < robCtl->busManager->devCount() )
//        {
//               //EC_WC_COMPLETE!=ds.wc_state
////            rt_printf("error :ds.working_counter < robCtl->busManager->devCount; domain: State %d , %d  .\n", ds.wc_state, ds.working_counter  );
////            rt_printf("error : EC_WC_COMPLETE!=ds.wc_state;domain: State %d , %d  .\n", ds.wc_state, ds.working_counter  );

//            addMsg( ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9031, -1 ,
//                    ds.working_counter, robCtl->busManager->devCount(),ds.wc_state );

//        }

        wkc_state=ds.wc_state;
//        wkc_count=ds.working_counter;
//        if (ds.working_counter < robCtl->busManager->devCount()
//                || (ds.wc_state != domain_state.wc_state && EC_WC_COMPLETE!=ds.wc_state))
//        {
        if (EC_WC_COMPLETE!=ds.wc_state)
        {

            slave_not_read_counter++;
            if(wkc_lost_max<slave_not_read_counter)
            {
                wkc_lost_max=slave_not_read_counter;
            }
            if(slave_not_read_counter>1 && slave_not_read_counter<wkcLostLimit)
            {
                if(0)
                {
                    if(1==slave_not_read_counter )
                    {
                        wkcRecordQueue.enqueue(-100000);
                    }
                    wkcRecordQueue.enqueue(ds.working_counter);
                    qDebug()<<"slave_not_read_counter"<<slave_not_read_counter<<"ds.wc_state"<<ds.wc_state
                                      <<"ds.working_counter"<<ds.working_counter<<"wkcRecordQueue"<<wkcRecordQueue;
                }

            }
            if(D_WKC_ERROR_NOTICE)
            {
                if(slave_not_read_counter>wkcLostLimit)//达瑞问题
                {
                    setMasterState( eMasterErr );
                    domainStateRrror = 0x01;
                    addMsg( ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9031, -1 ,
                            ds.working_counter, robCtl->busManager->devCount(),ds.wc_state,wkcLostLimit );
                    addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh", 9065, -1 );
                }
            }

            ret |= 1<<2;
            if (EC_WC_INCOMPLETE==ds.wc_state)
            {
                if(wkc_count>ds.working_counter)
                {
                    wkc_count=ds.working_counter;
                }
            }

        }
        else
        {
//            wkcRecordQueue.clear();
            slave_not_read_counter=0;
            domain_state = ds;
//            wkc_count=ds.working_counter;
        }

//        qDebug()<<"slave_not_read_counter"<<slave_not_read_counter<<"ds.wc_state"<<ds.wc_state
//                  <<"ds.working_counter"<<ds.working_counter;

        if(domainStateRrror )
        {
            domain_state = ds;
        }
    }
    else
    {
        domain_state = ds;
    }

    return ret;
}


int EcatMasterIgh::getEcatDeviceConfig_byEeprom(S_EcatDevInfo &devicePdoInfoOut ,int nodeIn)
{
    ec_slave_info_t slaveInfoReturned;
    if(ecrt_master_get_slave( master, nodeIn, &slaveInfoReturned )) {
        rt_printf("getEcatDeviceConfig===slave_info=====node=%d\n", nodeIn);
        return -1;
    }

    int tmpSyncCount=0;
    int tmpPdoCount=0;
    int tmpEntryCount=0;
    int tmpPdoIndexList[D_TMP_VECTOR_SIZE]={0};//sync的第一个pdo在ec_pdos数组中的索引号
    int tmpEntryIndexList[D_TMP_VECTOR_SIZE]={0};//pdo的第一个entry在ec_entries数组中的索引号

    devicePdoInfoOut.objConfig.ec_syncs.resize(D_TMP_VECTOR_SIZE) ;
    devicePdoInfoOut.objConfig.ec_pdos.resize(D_TMP_VECTOR_SIZE) ;
    devicePdoInfoOut.objConfig.ec_entries.resize(D_TMP_VECTOR_SIZE) ;

    for(int i=0; i< slaveInfoReturned.sync_count; i++)
    {
        ec_sync_info_t tmpSyncReturn ;
        if(ecrt_master_get_sync_manager( master, nodeIn, i, &tmpSyncReturn )) {
            rt_printf("ecrt_master_get_sync_manager===sync======slave_info.sync_count=%d\n", i);
            addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9021, -1, nodeIn );
            return -2;
        }
        devicePdoInfoOut.objConfig.ec_syncs[tmpSyncCount] = tmpSyncReturn ;
        tmpPdoIndexList[tmpSyncCount]=tmpPdoCount;
        tmpSyncCount++;

        for(int j=0; j< tmpSyncReturn.n_pdos; j++ )
        {
            ec_pdo_info_t tmpPdoReturn;
            if(ecrt_master_get_pdo( master, nodeIn, i, j, &tmpPdoReturn )) {
                rt_printf("ecrt_master_get_pdo====pdos=====sync.n_pdos=%d\n", j);
                addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9021, -1, nodeIn );
                return -3;
            }

            devicePdoInfoOut.objConfig.ec_pdos[tmpPdoCount] = tmpPdoReturn ;
            tmpEntryIndexList[tmpPdoCount]=tmpEntryCount;
            tmpPdoCount++;

            for(int k=0; k< tmpPdoReturn.n_entries; k++ )
            {
                ec_pdo_entry_info_t tmpEntryReturn;
                if(ecrt_master_get_pdo_entry( master, nodeIn, i, j, k, &tmpEntryReturn )) {
                    rt_printf("ecrt_master_get_pdo_entry====entries=====pdos.n_entries=%d\n", k);
                    addMsg(ENUM_MSG_ERROR, "EcatMaster", "EcatMasterIgh" , 9021, -1, nodeIn );
                    return -4;
                }
                devicePdoInfoOut.objConfig.ec_entries[tmpEntryCount] = tmpEntryReturn ;
                tmpEntryCount++;
            }
        }
    }

    devicePdoInfoOut.objConfig.ec_syncs.resize(tmpSyncCount) ;
    devicePdoInfoOut.objConfig.ec_pdos.resize(tmpPdoCount) ;
    devicePdoInfoOut.objConfig.ec_entries.resize(tmpEntryCount) ;

    //建立指针关系
    int k=0;
    for(int i=0;i<tmpSyncCount;i++ )
    {
//        if(tmpPdoIndexList[i]<devicePdoInfoOut.objConfig.ec_pdos.size())
//        {
//            devicePdoInfoOut.objConfig.ec_syncs[i].pdos
//                    = (ec_pdo_info_t *)&devicePdoInfoOut.objConfig.ec_pdos.at( tmpPdoIndexList[i] );
//        }
//        else
//        {
//            devicePdoInfoOut.objConfig.ec_syncs[i].pdos=NULL;
//        }
//        for( int j=0 ; j< devicePdoInfoOut.objConfig.ec_syncs.at(i).n_pdos ; j++, k++ )
//        {
//            devicePdoInfoOut.objConfig.ec_pdos[k].entries
//                    = (ec_pdo_entry_info_t *)&devicePdoInfoOut.objConfig.ec_entries.at( tmpEntryIndexList[k] );
//        }
        //syn->pdo 指向
        if(1<=devicePdoInfoOut.objConfig.ec_syncs[i].n_pdos)
        {
            devicePdoInfoOut.objConfig.ec_syncs[i].pdos
                    = (ec_pdo_info_t *)&devicePdoInfoOut.objConfig.ec_pdos.at( tmpPdoIndexList[i] );
        }
        else
        {
            devicePdoInfoOut.objConfig.ec_syncs[i].pdos=NULL;
        }
        //pdo->entry 指向
        for( int j=0 ; j< devicePdoInfoOut.objConfig.ec_syncs.at(i).n_pdos ; j++, k++ )
        {
            devicePdoInfoOut.objConfig.ec_pdos[k].entries
                    = (ec_pdo_entry_info_t *)&devicePdoInfoOut.objConfig.ec_entries.
                                            at( tmpEntryIndexList[k] );
        }
    }


    if(0>=tmpSyncCount)
    {
        qDebug()<<"get ethercat slave config failed, no syncs finded！node="<<nodeIn;
        return -1;
    }

    qDebug()<<"get ethercat slave config success！"<<nodeIn;
    return 1;
}

int EcatMasterIgh::getEcatIoDeviceConfig(S_EcatDevInfo &devicePdoInfo, int node)
{
    ec_slave_info_t slave_info;
    if(ecrt_master_get_slave( master, node, &slave_info )) {
        rt_printf("getEcatDeviceConfig===slave_info=====node=%d\n", node);
        return -1;
    }
    switch(slave_info.vendor_id)
    {
    case D_VENDOR_ID_BURKMORE_IO:
    {
        return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);
    }
    case D_VENDOR_ID_SOFTLINK:
    {
        return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);
    }
    case D_VENDOR_ID_YODA:
    {
        return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);
    }
    case D_VENDOR_ID_LeiSai_IO:
    {
        return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);
        if(D_VENDOR_ID_LeiSai_IO_EM06AXE1==slave_info.product_code
                ||D_VENDOR_ID_LeiSai_IO_EM32DXE1==slave_info.product_code
                ||D_VENDOR_ID_LeiSai_IO_EM32DXE4==slave_info.product_code)
        {
            return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);

        }
        else if(D_VENDOR_ID_LeiSai_IO_EM32DIE4==slave_info.product_code
                ||D_VENDOR_ID_LeiSai_IO_EM32DOE4==slave_info.product_code)
        {
            return getEcatIoPdoConfig_byCode(devicePdoInfo,
                                             slave_info.vendor_id,slave_info.product_code);

        }
        else
        {
            qDebug()<<"~~~~error:getEcatIoDeviceConfig ,unsupport product code"<<slave_info.product_code;
            return -1;
        }
        break;
    }
    case D_VENDOR_ID_SHANGHAI_XINGYANG:
    {
//        return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);
        if(D_VENDOR_ID_SHANGHAI_XINGYANG_ECATIOR2==slave_info.product_code)
        {
            return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);

        }
        else if(D_VENDOR_ID_SHANGHAI_XINGYANG_SMARTIOR1==slave_info.product_code)
        {
            return getEcatIoPdoConfig_byCode(devicePdoInfo,
                                             slave_info.vendor_id,slave_info.product_code);

//            return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);//默认pdo映射会变

        }
        else
        {
            rt_printf("D_VENDOR_ID_SHANGHAI_XINGYANG error getEcatDeviceConfig===slave_info=====node=%d\n", node);
            return -1;
        }
        break;
    }
    case D_VENDOR_ID_BECKHOFF:
    {

        if(D_VENDOR_ID_BECKHOFF_IO_EL3054==slave_info.product_code
                || D_VENDOR_ID_BECKHOFF_IO_EL3064==slave_info.product_code)
        {
            return getIoDevicePdoConfigByCode(devicePdoInfo,node);

        }
        else
        {
             return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);
        }
        break;
    }
    case D_VENDOR_ID_TECHSERVO_IO:
    {

        if(D_VENDOR_ID_TECHSERVO_IO_8000==slave_info.product_code)
        {
            return getIoDevicePdoConfigByCode(devicePdoInfo,node);

        }
        else
        {
             return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);
        }
        break;
    }
    case D_VENDOR_ID_TECHSERVO_C48IO:
    {

        if(D_VENDOR_ID_TECHSERVO_IO_80000800==slave_info.product_code)
        {
            return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);
//            return getIoDevicePdoConfigByCode(devicePdoInfo,node);

        }
        else
        {
             return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);
        }
        break;
    }
    default:
    {
        return getEcatDeviceConfig_byEeprom(devicePdoInfo,node);
//        getEcatIoPdoConfig_xml();
    }
    }

    return -2;

}

int EcatMasterIgh::getIoDevicePdoConfigByCode(S_EcatDevInfo &devicePdoInfo, int node)
{
    rt_printf("getIoDevicePdoConfigByCode=====node=%d\n", node);
    //todoForVision
    int vendor = devicePdoInfo.devInfo.vendorId;
    switch( vendor )
    {
//    case D_VENDOR_ID_LeiSai_IO:
//    {
//        devicePdoInfo.objConfig.ec_entries.resize( sizeof(leisai_encoder_pdo_entries)/sizeof(ec_pdo_entry_info_t) );
//        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(leisai_encoder_pdos)/sizeof(ec_pdo_info_t)  );
//        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(leisai_encoder_syncs)/sizeof(ec_sync_info_t)  );

//        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), leisai_encoder_pdo_entries, sizeof(leisai_encoder_pdo_entries) );
//        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), leisai_encoder_pdos, sizeof(leisai_encoder_pdos) );
//        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), leisai_encoder_syncs, sizeof(leisai_encoder_syncs) );

//        devicePdoInfo.objConfig.ec_pdos[0].entries
//                =&(devicePdoInfo.objConfig.ec_entries[0]);
//        devicePdoInfo.objConfig.ec_pdos[1].entries
//                =&(devicePdoInfo.objConfig.ec_entries[1]);
//        devicePdoInfo.objConfig.ec_pdos[2].entries
//                =&(devicePdoInfo.objConfig.ec_entries[4]);
//        devicePdoInfo.objConfig.ec_pdos[3].entries
//                =&(devicePdoInfo.objConfig.ec_entries[14]);
//        devicePdoInfo.objConfig.ec_pdos[4].entries
//                =&(devicePdoInfo.objConfig.ec_entries[24]);


//        devicePdoInfo.objConfig.ec_syncs.resize(4);
//        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
//        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
//        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
//        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
//    }
//        break;

    case D_VENDOR_ID_BECKHOFF:
    {

        if(D_VENDOR_ID_BECKHOFF_IO_EL3054==devicePdoInfo.devInfo.productCode
                || D_VENDOR_ID_BECKHOFF_IO_EL3064==devicePdoInfo.devInfo.productCode)
        {

            devicePdoInfo.objConfig.ec_entries.resize( sizeof(beckhoof_ai_pdo_entries)/sizeof(ec_pdo_entry_info_t) );
            devicePdoInfo.objConfig.ec_pdos.resize( sizeof(beckhoof_ai_pdos)/sizeof(ec_pdo_info_t)  );
            devicePdoInfo.objConfig.ec_syncs.resize( sizeof(beckhoof_ai_syncs)/sizeof(ec_sync_info_t)  );

            memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), beckhoof_ai_pdo_entries, sizeof(beckhoof_ai_pdo_entries) );
            memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), beckhoof_ai_pdos, sizeof(beckhoof_ai_pdos) );
            memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), beckhoof_ai_syncs, sizeof(beckhoof_ai_syncs) );

            devicePdoInfo.objConfig.ec_pdos[0].entries
                    =&(devicePdoInfo.objConfig.ec_entries[0]);
            devicePdoInfo.objConfig.ec_pdos[1].entries
                    =&(devicePdoInfo.objConfig.ec_entries[1]);
            devicePdoInfo.objConfig.ec_pdos[2].entries
                    =&(devicePdoInfo.objConfig.ec_entries[2]);
            devicePdoInfo.objConfig.ec_pdos[3].entries
                    =&(devicePdoInfo.objConfig.ec_entries[3]);

            devicePdoInfo.objConfig.ec_syncs.resize(4);
            devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[2].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        }
        else
        {
            qDebug()<<"error,getIoDevicePdoConfigByCode,unknow productCode"
                   <<devicePdoInfo.devInfo.productCode;
             return -1;
        }
        break;
    }
    case D_VENDOR_ID_TECHSERVO_IO:
    {

        if(D_VENDOR_ID_TECHSERVO_IO_8000==devicePdoInfo.devInfo.productCode)
        {

            devicePdoInfo.objConfig.ec_entries.resize( sizeof(taike_rio_pdo_entries)/sizeof(ec_pdo_entry_info_t) );
            devicePdoInfo.objConfig.ec_pdos.resize( sizeof(taike_rio_pdos)/sizeof(ec_pdo_info_t)  );
            devicePdoInfo.objConfig.ec_syncs.resize( sizeof(taike_rio_syncs)/sizeof(ec_sync_info_t)  );

            memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), taike_rio_pdo_entries, sizeof(taike_rio_pdo_entries) );
            memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), taike_rio_pdos, sizeof(taike_rio_pdos) );
            memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), taike_rio_syncs, sizeof(taike_rio_syncs) );

            devicePdoInfo.objConfig.ec_pdos[0].entries
                    =&(devicePdoInfo.objConfig.ec_entries[0]);
            devicePdoInfo.objConfig.ec_pdos[1].entries
                    =&(devicePdoInfo.objConfig.ec_entries[8]);
            devicePdoInfo.objConfig.ec_pdos[2].entries
                    =&(devicePdoInfo.objConfig.ec_entries[16]);


            devicePdoInfo.objConfig.ec_syncs.resize(4);
            devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
//            devicePdoInfo.objConfig.ec_syncs[2].pdos=NULL;
//            devicePdoInfo.objConfig.ec_syncs[3].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
            devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
            qDebug()<<"sucess,D_VENDOR_ID_TECHSERVO_IO_8000 2";
        }
        else
        {
            qDebug()<<"error,getIoDevicePdoConfigByCode,unknow productCode"
                   <<devicePdoInfo.devInfo.productCode;
             return -1;
        }
        break;
    }
    default:
    {
        qDebug()<<"error,getIoDevicePdoConfigByCode,unknow vendor"<<vendor;
        return -1;
    }
        break;
    }



    return 1;

}

int EcatMasterIgh::getEcatMotorPdoConfig(S_EcatDevInfo &devicePdoInfo)
{
    //
    int vendor = devicePdoInfo.devInfo.vendorId;
    switch( vendor )
    {
    case D_VENDOR_ID_TCR:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(tcr_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(tcr_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(tcr_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), tcr_entries, sizeof(tcr_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), tcr_pdos, sizeof(tcr_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), tcr_syncs, sizeof(tcr_syncs) );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_Delta:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(delta_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(delta_pdos)/sizeof(ec_pdo_info_t) );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(delta_syncs)/sizeof(ec_sync_info_t) );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), delta_entries, sizeof(delta_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), delta_pdos, sizeof(delta_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), delta_syncs, sizeof(delta_syncs)  );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_Sanyo:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(sanyo_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(sanyo_pdos)/sizeof(ec_pdo_info_t) );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(sanyo_syncs)/sizeof(ec_sync_info_t) );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), sanyo_entries, sizeof(sanyo_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), sanyo_pdos, sizeof(sanyo_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), sanyo_syncs, sizeof(sanyo_syncs) );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_LS:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(ls_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(ls_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(ls_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), ls_entries, sizeof(ls_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), ls_pdos, sizeof(ls_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), ls_syncs, sizeof(ls_syncs)  );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_Panasonic:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(sx_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(sx_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(sx_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), sx_entries, sizeof(sx_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), sx_pdos, sizeof(sx_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), sx_syncs, sizeof(sx_syncs) );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_Invt:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(invt_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(invt_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(invt_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), invt_entries, sizeof(invt_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), invt_pdos, sizeof(invt_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), invt_syncs, sizeof(invt_syncs) );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_BURKMORE_STEP_MOTOR:
    {
        if(D_VENDOR_ID_BURKMORE_STEP_MOTOR_4CHANNEL==devicePdoInfo.devInfo.productCode)
        {
            devicePdoInfo.objConfig.ec_entries.resize( sizeof(step4channel_pdo_entries)/sizeof(ec_pdo_entry_info_t) );
            devicePdoInfo.objConfig.ec_pdos.resize( sizeof(step4channel_pdos)/sizeof(ec_pdo_info_t)  );
            devicePdoInfo.objConfig.ec_syncs.resize( sizeof(step4channel_syncs)/sizeof(ec_sync_info_t)  );

            memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), step4channel_pdo_entries, sizeof(step4channel_pdo_entries) );
            memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), step4channel_pdos, sizeof(step4channel_pdos) );
            memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), step4channel_syncs, sizeof(step4channel_syncs) );
            qDebug()<<"D_VENDOR_ID_BURKMORE_STEP_MOTOR_4CHANNEL";

            //建立指针关系
//            int tmpSyncCount=4;
//            int k=0;
//            for(int i=0;i<tmpSyncCount;i++ )
//            {

//                //syn->pdo 指向
//                if(1<=devicePdoInfo.objConfig.ec_syncs[i].n_pdos)
//                {
//                    devicePdoInfo.objConfig.ec_syncs[i].pdos
//                            = (ec_pdo_info_t *)&devicePdoInfo.objConfig.ec_pdos.at( tmpPdoIndexList[i] );
//                }
//                else
//                {
//                    devicePdoInfo.objConfig.ec_syncs[i].pdos=NULL;
//                }
//                //pdo->entry 指向
//                for( int j=0 ; j< devicePdoInfo.objConfig.ec_syncs.at(i).n_pdos ; j++, k++ )
//                {
//                    devicePdoInfo.objConfig.ec_pdos[k].entries
//                            = (ec_pdo_entry_info_t *)&devicePdoInfo.objConfig.ec_entries.
//                                                    at( tmpEntryIndexList[k] );
//                }
//            }
            int tmpIndex=0;
            devicePdoInfo.objConfig.ec_pdos[0].entries
                    =&(devicePdoInfo.objConfig.ec_entries[tmpIndex]);

            tmpIndex+=devicePdoInfo.objConfig.ec_pdos[0].n_entries;
            devicePdoInfo.objConfig.ec_pdos[1].entries
                    =&(devicePdoInfo.objConfig.ec_entries[tmpIndex]);

            tmpIndex+=devicePdoInfo.objConfig.ec_pdos[1].n_entries;
            devicePdoInfo.objConfig.ec_pdos[2].entries
                    =&(devicePdoInfo.objConfig.ec_entries[tmpIndex]);

            tmpIndex+=devicePdoInfo.objConfig.ec_pdos[2].n_entries;
            devicePdoInfo.objConfig.ec_pdos[3].entries
                    =&(devicePdoInfo.objConfig.ec_entries[tmpIndex]);

            tmpIndex+=devicePdoInfo.objConfig.ec_pdos[3].n_entries;
            devicePdoInfo.objConfig.ec_pdos[4].entries
                    =&(devicePdoInfo.objConfig.ec_entries[tmpIndex]);

            tmpIndex+=devicePdoInfo.objConfig.ec_pdos[4].n_entries;
            devicePdoInfo.objConfig.ec_pdos[5].entries
                    =&(devicePdoInfo.objConfig.ec_entries[tmpIndex]);

            tmpIndex+=devicePdoInfo.objConfig.ec_pdos[5].n_entries;
            devicePdoInfo.objConfig.ec_pdos[6].entries
                    =&(devicePdoInfo.objConfig.ec_entries[tmpIndex]);

            tmpIndex+=devicePdoInfo.objConfig.ec_pdos[6].n_entries;
            devicePdoInfo.objConfig.ec_pdos[7].entries
                    =&(devicePdoInfo.objConfig.ec_entries[tmpIndex]);



            devicePdoInfo.objConfig.ec_syncs.resize(4);
            devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
            devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[4]);
        }
        else
        {
            devicePdoInfo.objConfig.ec_entries.resize( sizeof(step_entries)/sizeof(ec_pdo_entry_info_t) );
            devicePdoInfo.objConfig.ec_pdos.resize( sizeof(step_pdos)/sizeof(ec_pdo_info_t)  );
            devicePdoInfo.objConfig.ec_syncs.resize( sizeof(step_syncs)/sizeof(ec_sync_info_t)  );

            memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), step_entries, sizeof(step_entries) );
            memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), step_pdos, sizeof(step_pdos) );
            memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), step_syncs, sizeof(step_syncs) );
            qDebug()<<"D_VENDOR_ID_BURKMORE_STEP_MOTOR_1CHANNEL";


            devicePdoInfo.objConfig.ec_pdos[0].entries
                    =&(devicePdoInfo.objConfig.ec_entries[0]);
            devicePdoInfo.objConfig.ec_pdos[1].entries
                    =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

            devicePdoInfo.objConfig.ec_syncs.resize(4);
            devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
            devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
            devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
        }

    }
        break;
    case D_VENDOR_ID_Inovance:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(inovance_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(inovance_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(inovance_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), inovance_entries, sizeof(inovance_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), inovance_pdos, sizeof(inovance_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), inovance_syncs, sizeof(inovance_syncs) );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_QingNengDeChuang:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(qingNengDeChuang_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(qingNengDeChuang_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(qingNengDeChuang_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), qingNengDeChuang_entries, sizeof(qingNengDeChuang_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), qingNengDeChuang_pdos, sizeof(qingNengDeChuang_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), qingNengDeChuang_syncs, sizeof(qingNengDeChuang_syncs) );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_TECHSERVO:
    {
        //新驱动不支持，旧驱动支持
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(taikeMotorPT_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(taikeMotorPT_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(taikeMotorPT_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), taikeMotorPT_entries, sizeof(taikeMotorPT_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), taikeMotorPT_pdos, sizeof(taikeMotorPT_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), taikeMotorPT_syncs, sizeof(taikeMotorPT_syncs) );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_LeiSai_IO:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(motor_leisai_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(motor_leisai_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(motor_leisai_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), motor_leisai_entries, sizeof(motor_leisai_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), motor_leisai_pdos, sizeof(motor_leisai_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), motor_leisai_syncs, sizeof(motor_leisai_syncs) );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_Servotronix:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(servotronix_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(servotronix_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(servotronix_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), servotronix_entries, sizeof(servotronix_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), servotronix_pdos, sizeof(servotronix_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), servotronix_syncs, sizeof(servotronix_syncs) );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    case D_VENDOR_ID_YiLaiSi:
    {
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(elesyMotor_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(elesyMotor_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(elesyMotor_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), elesyMotor_entries, sizeof(elesyMotor_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), elesyMotor_pdos, sizeof(elesyMotor_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), elesyMotor_syncs, sizeof(elesyMotor_syncs) );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    default:
    {
        qDebug()<<"\n警告:使用通用的伺服PDO配置 vendorId"<<vendor;
        devicePdoInfo.objConfig.ec_entries.resize( sizeof(motor_entries)/sizeof(ec_pdo_entry_info_t) );
        devicePdoInfo.objConfig.ec_pdos.resize( sizeof(motor_pdos)/sizeof(ec_pdo_info_t)  );
        devicePdoInfo.objConfig.ec_syncs.resize( sizeof(motor_syncs)/sizeof(ec_sync_info_t)  );

        memcpy(&(devicePdoInfo.objConfig.ec_entries[0]), motor_entries, sizeof(motor_entries) );
        memcpy(&(devicePdoInfo.objConfig.ec_pdos[0]), motor_pdos, sizeof(motor_pdos) );
        memcpy(&(devicePdoInfo.objConfig.ec_syncs[0]), motor_syncs, sizeof(motor_syncs)  );


        devicePdoInfo.objConfig.ec_pdos[0].entries
                =&(devicePdoInfo.objConfig.ec_entries[0]);
        devicePdoInfo.objConfig.ec_pdos[1].entries
                =&(devicePdoInfo.objConfig.ec_entries[devicePdoInfo.objConfig.ec_pdos[0].n_entries]);

        devicePdoInfo.objConfig.ec_syncs.resize(4);
        devicePdoInfo.objConfig.ec_syncs[0].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[1].pdos=NULL;
        devicePdoInfo.objConfig.ec_syncs[2].pdos=&(devicePdoInfo.objConfig.ec_pdos[0]);
        devicePdoInfo.objConfig.ec_syncs[3].pdos=&(devicePdoInfo.objConfig.ec_pdos[1]);
    }
        break;
    }




    qDebug()<<"getBusSlaveConfig";
    return 1;
}

void EcatMasterIgh::addMsg(int messageLevel, std::string componentName, std::string messageType,
                           int messageCode, int robotId,
                           int parameter1, int parameter2, int parameter3, int parameter4)
{
    Message tmpMsg;
    tmpMsg.MessageLevel = messageLevel;
    tmpMsg.componentClassName = componentName;
    tmpMsg.messageType = messageType;
    tmpMsg.robotId = robotId;
    tmpMsg.messageCode = messageCode;
//    tmpMsg.time = t1.tv_sec;

    QString infomationStr;

    switch(messageCode)
    {
    case 9073:
    {
        infomationStr =  QObject::tr("ethercat主站未开启!!!");
        break;

    }
    case 9072:
    {
        infomationStr =  QObject::tr("设置参考时钟失败，ethercat主站处于错误锁死状态!!!");
        break;

    }
    case 9071:
    {
        infomationStr =  QObject::tr("获取参考时钟失败次数(%1)超过允许值，ethercat主站处于错误锁死状态!!!").arg(parameter1);
        break;

    }
    case 9070:
    {
        infomationStr =  QObject::tr("别名(%1)io模块初始化sdo失败,sdo序号%2 。ethercat进入琐死状态!").arg(parameter1).arg(parameter2);
        break;

    }
    case 9069:
    {
        infomationStr =  QObject::tr("编码器读取模块pdo配置失败，ethercat主站处于错误锁死状态!!!");
        break;

    }
    case 9068:
    {
        infomationStr =  QObject::tr("io设备pdo配置失败，ethercat主站处于错误锁死状态!!!");
        break;

    }
    case 9067:
    {
        infomationStr =  QObject::tr("伺服驱动器pdo配置失败，ethercat主站处于错误锁死状态!!!");
        break;

    }
    case 9066:
    {
        infomationStr =  QObject::tr("ethercat主站超过(%1)次未成功进入OP状态,请给驱动器断电后再上电并启动系统!!!").arg(parameter1);
        break;

    }
    case 9065:
    {
        infomationStr =  QObject::tr("ethercat主站处于错误锁死状态，请重启控制器!!!");
        break;

    }
    case 9050:
    {
        infomationStr =  QObject::tr("别名(%1)电机初始化sdo失败,sdo序号%2 。ethercat进入琐死状态!").arg(parameter1).arg(parameter2);
        break;

    }
    case 9049:
    {
        infomationStr =  QObject::tr("别名(%1)编码器读取模块初始化sdo失败,sdo序号%2 。ethercat进入琐死状态!").arg(parameter1).arg(parameter2);
        break;

    }
    case 9048:
    {
        infomationStr =  QObject::tr("ethercat checkConfig.ini文件读取失败 !");
        break;

    }
//    case 9009:
//    {
//        infomationStr =  QObject::tr("ethercat checkConfig.ini文件缺少 ecatCustommax参数 !");
//        break;

//    }
//    case 9008:
//    {
//        infomationStr =  QObject::tr("ethercat checkConfig.ini文件缺少 ecatSendMax参数 !");
//        break;

//    }
//    case 9007:
//    {
//        infomationStr =  QObject::tr("ethercat checkConfig.ini文件缺少 ecatReceiveMax参数 !");
//        break;

//    }

//    case 9006:
//    {
//        infomationStr =  QObject::tr("ethercat checkConfig.ini文件缺少 ecatPeriodTimerOffsetMax参数 !");
//        break;

//    }
//    case 9005:
//    {
//        infomationStr =  QObject::tr("ethercat checkConfig.ini文件缺少 wkcLostLimit参数 !");
//        break;

//    }

    case 9004:
    {
        infomationStr =  QObject::tr("ethercat period timer(%1 us) exceed max limit(%2 us),cycle_ns=%3,cycle_us=%4  !")
                .arg(parameter1).arg(parameter2).arg(parameter3).arg(parameter4);

    }
        break;
    case 9003:
    {
        infomationStr =  QObject::tr("ethercat period timer(%1 us) exceed min limit(%2 us),cycle_ns=%3,cycle_us=%4  !")
                .arg(parameter1).arg(parameter2).arg(parameter3).arg(parameter4);

    }
        break;

    case 9002:
    {
        infomationStr =  QObject::tr("系统初始化完成，请您操作(ETHERCAT) !");
        break;

    }
    case 9306:
    {
        infomationStr = QObject::tr( "ethercat io别名(%1)busDev.xml中node(%2)与实际物理node不一致，请检查物理接线或配置")
                .arg(parameter1).arg(parameter2);
    }
    case 9305:
    {
        infomationStr = QObject::tr( "ethercat io别名%1在总线配置中没有找到!").arg(parameter1) ;
    }
        break;
    case 9304:
    {
        infomationStr =  QObject::tr("ethercat custom time(%1) exceed limit(%2 us) !")
                .arg(parameter1).arg(parameter2);
    }
        break;
    case 9303:
    {
        infomationStr =  QObject::tr("ethercat send time(%1) exceed limit(%2 us) !")
                .arg(parameter1).arg(parameter2);

    }
        break;
    case 9302:
    {
        infomationStr =  QObject::tr("ethercat receive time(%1 us) exceed limit(%2 us) !")
                .arg(parameter1).arg(parameter2);
    }
        break;
    case 9301:
    {
        infomationStr = QObject::tr( "机器人轴ecat总线错误，别名(%1)在busDev.xml中的node(%2)与实际物理的node不一致，请检查物理接线或配置")
                .arg(parameter1).arg(parameter2);
    }
        break;
    case 9300:
    {
        infomationStr = QObject::tr( "机器人轴( ethercat motor别名%1)在ecat总线中没有检测到!").arg(parameter1) ;
    }
        break;


    case 9010:
    {
        infomationStr =  QObject::tr("读取机器人配置信息出错 !");

    }
        break;
    case 9011:
    {
        infomationStr =  QObject::tr("读取ethercat总线配置信息出错!");

    }
        break;
    case 9012:
    {
        infomationStr =  QObject::tr("请求ethercat主站无响应！");

    }
        break;
    case 9013:
    {
        infomationStr =  QObject::tr("ethercat配置过程：域数据寄存器配置失败！");

    }
        break;
    case 9014:
    {
        infomationStr =  QObject::tr("从站别名检测错误！") +QString::number(parameter1);
    }
        break;
    case 9015:
    {
        infomationStr =  QObject::tr("初始化设备失败！");

    }
        break;
    case 9016:
    {
        infomationStr =  QObject::tr("激活ethercat主站失败,请检查pdo映射配置！");

    }
        break;
    case 9017:
    {
        infomationStr =  QObject::tr("无效的总线设备, 别名：")
                + QString::number(parameter1);

    }
        break;
    case 9018:
    {
        infomationStr =  QObject::tr("无效的机器人设备, 别名:");

    }
        break;
    case 9019:
    {
        infomationStr= QObject::tr("从站配置失败：PDO映射错误！站号（按位算）:")
                + QString::number(parameter1);

    }
        break;
    case 9020:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",轴")
                + QString::number(parameter1+1)
                +  " ," +QObject::tr("回零步骤操作超时 1 !");
    }
        break;
    case 9021:
    {
        infomationStr =  QObject::tr("获取ethercat从站配置失败, 站号:") + QString::number(parameter1);

    }
        break;
    case 9022:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",轴");
        infomationStr = infomationStr + QString::number(parameter1+1);
        infomationStr = infomationStr +  " ," +QObject::tr("主电源缺相！");

    }
        break;
    case 9023:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",轴");
        infomationStr = infomationStr + QString::number(parameter1+1);
        infomationStr = infomationStr +  " ," +QObject::tr("电池电量不足！");

    }
        break;
    case 9024:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",轴");
        infomationStr = infomationStr + QString::number(parameter1+1);
        infomationStr = infomationStr +  " ," +QObject::tr("扭矩指令过大！");

    }
        break;
    case 9025:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",轴");
        infomationStr = infomationStr + QString::number(parameter1+1);
        infomationStr = infomationStr +  " ," +QObject::tr("速度指令过大！");

    }
        break;
    case 9026:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",轴");
        infomationStr = infomationStr + QString::number(parameter1+1);
        infomationStr = infomationStr + " ," + QObject::tr("过载警告!");

    }
        break;
    case 9027:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",轴");
        infomationStr = infomationStr + QString::number(parameter1+1);
        infomationStr = infomationStr +  " ," +QObject::tr("选定容量警告!");

    }
        break;
    case 9028:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",轴");
        infomationStr = infomationStr + QString::number(parameter1+1);
        infomationStr = infomationStr +  " ," +QObject::tr("低电压警告！");

    }
        break;
    case 9029:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",轴");
        infomationStr = infomationStr + QString::number(parameter1+1);
        infomationStr = infomationStr +  " ," +QObject::tr("EMG警告！");
    }
        break;
    case 9030:
    {
        infomationStr = QObject::tr("域数据读写错误！");

    }
    case 9031:
    {
        int tmpNodeId=parameter1/3;

        infomationStr =  QObject::tr("ethercat通信WKC异常,working_counter(%1)，总线设备数量(%2)，"
                                     "wkc_state=%3,wkcLostLimit=%4。")
                .arg(parameter1).arg(parameter2).arg(parameter3).arg(parameter4);
        infomationStr += QObject::tr("可能故障线路位于节点%1与节点%2之间(节点编号从0开始)").arg(tmpNodeId-1).arg(tmpNodeId);

    }
        break;
    case 9032:
    {
        infomationStr = QObject::tr("控制器运行发生错误，多次定时间隔小于20us！");

    }
        break;
    case 9033:
    {
        infomationStr =  QObject::tr("总线设备存在重复别名:")
                + QString::number(parameter1+1)
                + QString::number(parameter2);
    }
        break;
//    case 9034:
//    {
//        QString tempError;
//        tempError.clear();
//        tempError.sprintf("%02x",parameter2);
//        infomationStr =  QObject::tr("伺服报警:机器人:")  + QString::number(robotId)
//                + QObject::tr(", 轴:") + QString::number(parameter1+1)
//                + QObject::tr(", 错误码:")  + tempError+" ,"
//                + EthercatError::geterror( parameter3, parameter2 );
//    }
//        break;
    case 9035:
    {
        infomationStr =  QObject::tr("ethercat 驱动未启动!");
    }
        break;
    case 9036:
    {
        infomationStr=  QObject::tr("ethercat 设备启动失败, 请尝试重启！设备节点:")+ QString::number(parameter1);
    }
        break;
    case 9037:
    {
        infomationStr =  QObject::tr("ethercat 设备检测失败: 数目错误: ") + QString::number(parameter1);
    }
        break;
    case 9038:
    {
        infomationStr =  QObject::tr("ethercat 设备检测: 数目为零错误!");

    }
        break;
    case 9039:
    {
        infomationStr =  QObject::tr("ethercat 设备长时间没有响应, 请检查网卡或网络状态，并重启控制系统！");

    }
        break;

    case 9042:
    {
        infomationStr =  QObject::tr("ethercat 获取从站配置信息失败,node=") + QString::number(parameter1);
    }
        break;
    case 9043:
    {
        infomationStr =  QObject::tr("ethercat通信异常,有响应的从站数量(%1)不等于用户配置的总线设备数量(%2)!")
                .arg(parameter1).arg(parameter2);
    }
        break;

    case 9044:
    {
        infomationStr =  QObject::tr("ethercat状态异常,有从站不处于ＯＰ状态，stataCode=(%1) !")
                .arg(parameter1);
    }
        break;
    case 9045:
    {
        infomationStr =  QObject::tr("ethercat主站开启失败，找不到网卡 !")
                .arg(parameter1);
    }
        break;

    case 9046:
    {
        infomationStr =  QObject::tr("ethercat从站(nodeId=%1)退出ＯＰ状态,当前状态＝(%2) !")
                .arg(parameter1).arg(parameter2);
    }
        break;

    case 9047:
    {
        infomationStr =  QObject::tr("ethercat从站(nodeId=%1)有错误发生,当前状态＝(%2) !")
                .arg(parameter1).arg(parameter2);
        break;

    }
    default:
    {

    }
    }

    tmpMsg.MessageInformation = infomationStr.toStdString();
    MessageLog::getInstance()->addMessage(tmpMsg);

}




//bool EcatMasterIgh::sdoRealtimeRead( ec_sdo_request_t *pSdoRequest,
//                                     int pos, void *val , int byteNum, int offset )
//{
//    Q_UNUSED(pos)
//    switch( ecrt_sdo_request_state( pSdoRequest ))
//    {
//    case EC_REQUEST_UNUSED:
//        ecrt_sdo_request_read( pSdoRequest );
//        return false;
//    case EC_REQUEST_BUSY:
//        //rt_printf("Still Read busy...\n");
//        return false;
//    case EC_REQUEST_SUCCESS:
//    {
//        switch( byteNum )
//        {
//        case 1:
//        {
//            quint8 *tmp = (quint8 *)val;
//            *tmp = EC_READ_U8( ecrt_sdo_request_data( pSdoRequest ) + offset);
//        }
//            break;
//        case 2:
//        {
//            unsigned short *tmp1 = (unsigned short *)val;
//            *tmp1 = EC_READ_U16( ecrt_sdo_request_data( pSdoRequest ) + offset);
//        }
//            break;
//        case 4:
//        {
//            unsigned int *tmp2 = (unsigned int *)val;
//            *tmp2 = EC_READ_U32( ecrt_sdo_request_data( pSdoRequest ) + offset);
//        }
//            break;
//        default:
//            break;
//        }
//        ecrt_sdo_request_read( pSdoRequest );
//    }
//        return true;
//    case EC_REQUEST_ERROR:
//        //            rt_printf( "fail to read sdo\n" );
//        ecrt_sdo_request_read( pSdoRequest );   //重复写
//        return false;
//    }
//    return true;
//}

//bool EcatMasterIgh::sdoRealtimeWrite( ec_sdo_request_t *pSdoRequest, int pos,  int v , int byteNum, int offset )
//{
//    Q_UNUSED(byteNum)
//    Q_UNUSED(pos)
//    switch( ecrt_sdo_request_state( pSdoRequest ))
//    {
//    case EC_REQUEST_UNUSED:
//        ecrt_sdo_request_write( pSdoRequest );
//        return false;
//    case EC_REQUEST_BUSY:
//        //rt_printf("Still Read busy...\n");
//        return false;
//    case EC_REQUEST_SUCCESS:
//        EC_WRITE_U32( ecrt_sdo_request_data( pSdoRequest ) + offset, (unsigned int)v );
//        ecrt_sdo_request_write( pSdoRequest );
//        //rt_printf( "success to write sdo\n" );
//        return true;
//    case EC_REQUEST_ERROR:
//        //rt_printf( "fail to write sdo\n" );
//        ecrt_sdo_request_write( pSdoRequest );   //重复写
//        return false;
//    }
//    return true;
//}

